I’m trying to find a nice way to compare two strings when reading line by line in parallel.
The reason i want to do that without using equals method or such is because the strings are not exactly the same, to be more accurate i’ll give an example.
String s1 = "aaa\nbbb\nccc\ddd"
String s2 = "aaa\n\rbbb\n\rccc\n\rddd"
As u can see both strings has same values when we are looking line by line (though are not completly equal since s2 has also \r in it).
Now, i know i can use some remove method to clean that “\r” but since the string can be very large, i prefer looping row by row and once the strings are not equal to break my logic.
In other words i prefer iterating only the needed rows instead of cleanning the entrie string from \r.
edited: i am not reading from a file. these are plain strings.
Any ideas 🙂 ?
Since you said the string can be very large, I guess you are reading from a file. When you use a BufferedReader and use the
readLine();method, you will get line by line, without line separators. Now, you can useequals().