Java: String compare library that returns diff value as int?

Is there a library or even a standard API call that allows me to separate two lines and get the number of diff characters as int? I would not mind other functions as long as I can get a more diff programmatic result (like int) instead of just outputting all diff read by the user.

+3
source share
2 answers

I think you want Leveshtein distance - this tells you how many changes (insert, delete or replace) are needed to convert one line to another.

For example, the difference between abcdeand abcdefis 1, because you insert fafter the last position in abcdeto get abcdef.

The difference between abcdeand is abcdfalso equal to 1, since you replace ein the first row fto get the second.

The difference between abcdeand abdeis 1, because you delete cin the first row to get the second.

Here is the implementation in Java .

+5
source

I don’t know of any standard API calls, but you can see this question for links to third-party libraries (no wonder - Google, Apache Commons ...)

How to execute string diffs in Java?
How to execute string diffs in java?

+1

Source: https://habr.com/ru/post/1741309/


All Articles