0

Not entirely sure but my two arrays sorted1 and sorted2 should be equal to each other. However, for some reason I cannot figure out, when doing sorted1.equals(sorted2) I am returning false. Any idea why?

    public static void main(String[] args) {
        String a = "fired";
        String b = "fried";

        //System.out.println(anaHashMap(a, b));
        System.out.println(anaSort(a, b));

    }

    public static boolean anaSort(String a, String b) {
        char[] sorted1 = a.toLowerCase().toCharArray();
        char[] sorted2 = b.toLowerCase().toCharArray();
        Arrays.sort(sorted1);
        Arrays.sort(sorted2);

        System.out.println(sorted1);
        System.out.println(sorted2);
        
        if (sorted1.equals(sorted2)) {
            return true;
        }
        return false;
    }
}

0 Answers0