java - How to check a String's character not matching with other character of another String -
i have 2 strings i.e
string test1 = "if want succeed work hard.best of luck" . string test2 = "if want succeed work hard.best of yuck" .
basically , these dummy test strings have taken reference here.in , have strings have more 10000 lines of character.
i want check these strings equal or not . know .equals compare both strings value return boolean value. want check @ character didn't match.
i tried :-
for(int i=0 ; i<=test1.length();i++){ for(int j=0 ; j<=test2.length();j++){ if (test1.charat(i)==test2.charat(j)){ system.out.println("matched "+test1.charat(i)+" "+test2.charat(j)); } else{ system.out.println("not matched "+test1.charat(i)+" "+test2.charat(j)); } } }
but code check each character of test1 string every character of test2 , print. want check each character of test1 each character test2.
you have difference
method in stringutils apache library. return portion of string different.
also have couple more useful methods there (i.e. indexofdifference
return index difference starts or getlevenshteindistance
return number of changes need applied 1 string equal other) combination of can want.
other option more complicated usage can external library (one can java-dif-utils).
Comments
Post a Comment