I trying to compare 2 strings in Java to determine if they are the same:
System.out.println("app version: "+ appversion + " latest version: "+ latestversion);
if(!appversion.equals(latestversion))
{
System.out.println("not the same");
}
However this is giving me unexpected results given the outputs:
app version: v1.1.2 latest version: v1.1.2
not the same
I have used .replaceAll("\\s",""); to remove any whitespaces from the strings with no success.
There is probably a very obvious answer to this but can anyone tell me what i’m doing wrong?
Instead of .replaceAll() method, use trim() method to remove white space while comparing String variables.
change your code as follows as,