Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Line diff with context in Java

Tags:

java

diff

Is there a Java lib for line-based diff between multi-line text chunks, that supports before/after context lines, similarly to diff -C in the Unix toolkit?

For example, suppose the first chunk is

a
b
foo
c
d

and the second chunk is

a
b
goo
c
d

then diffing with one line of context should produce something like:

 b
-foo
+goo
 c

Preferably, this should be done using a native Java lib, not calling diff as an external process.

like image 536
Little Bobby Tables Avatar asked Jul 25 '26 02:07

Little Bobby Tables


1 Answers

Java doesn't have anything to perform diff out of the box. But you can use this java library. This doesn't require you to call a process like diff

like image 115
shazin Avatar answered Jul 27 '26 17:07

shazin