.equals() method not comparing two Strings in java

Its usually happen when we try to compare Two String in java even if both the Strings are same it doesn’t compare because of space and we don’t focus on that

to solve this problem use trim() method

eg

String str1 = “evaavi.com”;
String str2= “evaavi.com”;
if(str1.trim().equals(str2.trim()))
{
System.out.println(“Hello evaavi.com”);
}

Leave a Reply