String str="inputstring";
StringBuilder sb=new StringBuilder(str);
String rev=sb.reverse().toString();
//System.out.println(sb+" "+rev); //this prints the same reverse text
if(rev.equals(sb))
System.out.println("Equal");
else
System.out.println("Not Equal");
When I print this code StringBuilder and String prints the same output as "gnirtstupni gnirtstupni", but when I checked whether they are equal using if condition they print "Not Equal".
This is really confusing, please explain.