This is extremely odd. I am simply comparing two strings, which are the same, but they aren't..
are you sure they are the same strings ???
try get bytes and compare them (by bytes) or use codepoints
try {
byte[] bytesStr1 = Str1.getBytes("UTF-8");
byte[] bytesStr2= Str2.getBytes("UTF-8");
if(bytesStr1.length!=bytesStr.length)log("no match = size");
for(int b=0;b<bytesStr1.length;b++) {
if(bytesStr1[b] != bytesStr2[b])
return log("no match at pos: "+ b);
}
} catch (UnsupportedEncodingException e) {
// handle exception here
}
there could be many reasons why the string comparison fails -
for example
- space vs. non breaking space <- trim will not help you here
simple example:
String oldString = "\uD800";
String newString = new String(oldString);
String newString = new String(oldString.getBytes("UTF-8"), "UTF-8");
newString.equals(oldString) // ???? false
small appeal:
most of your(by this i mean most people here) problems can be solved by reading and understanding the basics :) - but instead you are all "drowning" from big "water"
Okay, I tried what you said and went byte by byte, but they were all the same. Also, the lengths were the same.. – Ruchir Baronia
so this mean that both strings "in your definition" are equals
instead of compare method you can use :
int pos = String.indexOf(String); //this will return you the firs position where the two strings don't match
- method implementation is similar to method which i wrote on the beginning of this post
lecture:
https://docs.oracle.com/javase/tutorial/java/data/comparestrings.html
now when we we code for android I recommend to take special attention - because google is rewriting most of java classes by itself String class from Oracle is not the same as Google String class because they don't run straight on ORACLE JVM !!! - see ART (Android Runtime) - every time when i visit google & browse repos i see code changes in google api & source code of android i see much more things rewrite in pure c (as native) - google wants to break with proprietary oracle java thus is using more of open jdk implementations