Sorting Map keys when keys are arrays

Viewed 66

I have a HashMap<Float[], Integer> and I'll probably need to convert it to TreeMap. How will keys (i.e. arrays) of TreeMap be sorted? By their first elements?

I was going to run a simple test but it resulted in error somehow:

public class treeMapTest {
    public static void main(String[] args) {
        Integer arr1[] = {9, 0, 3};
        Integer arr2[] = {2, 2, 2};
        Integer arr3[] = {4, 2, 1};

        TreeMap<Integer[], Integer> tm = new TreeMap<Integer[], Integer>();
        tm.put(arr1, 7);
        tm.put(arr2, 7);
        tm.put(arr3, 7);

        System.out.println(tm);
    }
}

Thank you.

5 Answers
Related