开发者

In java how would you compare two StringBuilders and copy only the difference of the two, into one

In java is there any elegant way to compare two different StringBuilders and copy only the difference of the two, into on开发者_C百科e?

Sb1 = "Hello World"
Sb2 = "Hello World says the lazy dog"

Appending ONLY the additional characters

Sb1 = "Hello World says the lazy dog";

I'm looking for some type of native API call that would closely mimic a unix diff and append command without going through messy for loops.

I'm using this to accumulate a log message that is continuously being pulled from a server. since im looking for a chronological order I would be seeking an appending at the end


This seems to be what you are looking for:

http://commons.apache.org

StringUtils.difference(java.lang.String, java.lang.String)

But for logs this seems like very ineffective if you know that you always going to pull same string plus some delta that was added since last pull than just keep the length form the previous time and do the

JDKs's String.substring(int previousLength)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜