0

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?

RJP
  • 385
  • 5
  • 19
  • 1
    Please search first for [java array equality test](https://www.google.com/search?q=site:stackoverflow.com+java+array+equality+test). It's all easy to find if you just look. – Hovercraft Full Of Eels Aug 02 '17 at 01:53
  • I totally forgot Arrays does not override the equals method. I feel so dumb. – RJP Aug 02 '17 at 02:01

0 Answers0