This is my code snipped to check if the two strings are anagrams of each other:
String str="jesus";
String str2="susej";
char []c1=str.toCharArray();
char []c2=str2.toCharArray();
Arrays.sort(c2);
Arrays.sort(c1);
System.out.println(c2); //ejssu
System.out.println(c1); //ejssu
System.out.println(c1.equals(c2)); //false
I thought that the ==
operator will return false since they do not share the same memory reference. Isnt the equals
method supposed to check if the value of the two objects are the same? I thought this would return true
. Why am I returning false?