1

In java is there any elegant way to compare two different StringBuilders and copy only the difference of the two, into one?

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

stackoverflow
  • 18,348
  • 50
  • 129
  • 196

1 Answers1

1

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)

Boris Daich
  • 2,431
  • 3
  • 23
  • 27