I have 2 Strings that are frustating me a lot. They contain, aparently, the same text, but when comparing them Java don't say that.
The text is "La Coruña". One string is returned via Google Geocoder, and the other is hardcoded by me.
I've tried equals()
which returns false, equalsIgnoreCase()
which returns false, contains()
which returns false, compareTo()
which doesn't return 0 (being 0 that are equals).
Then I dumped the strings into byte arrays with getBytes("UTF-8")
method on each.
Again, equals()
with returns false, Arrays.compare(array1, array2)
false too.
Arrays.compare()
returns false when the length of each arrays are different or when a value in same position are different. So I printed both arrays and... surprise!! The content was different.
Like this:
Array1 [76, 97, 32, 67, 111, 114, 117, -61, -79, 97]
Array2 [76, 97, 32, 67, 111, 114, 117, -47, -127, 97]
The question is WHY is this happening and how can make them equals so I can succesfully compare. My guess is that Google is using some kind of encoding ("La Coruña" contains ñ char) that differs from the other hardcoded String.
Please, give me some help
Thanks in advance.