You'll need to implement your own logic in order for your key to be Comparable, as Johannes' comment points out. You could create a class that implements Comparator and pass it as argument at the initialization of the TreeMap.
Note that the default/overriden compare method would also be valid, as arrays are just Objects.
You could even implement all the logics for non-comparable Object keys you wish to insert in different Maps in a single class:
public class NonCompObjectKeyComparator implements Comparator<Object>
{
@Override
public int compare(Object o1, Object o2)
{
if (o1 instanceof int[][])
{
//((int[][])o1),((int[][])o2)//
}
else if (o1 instanceof String[])
{
//((String[])o1),((String[])o2)//
}
else if (o1 instanceof <OtherNonComparableObjType>)
{
//...
}
//...
return 0;
}
}
And then you got your überComparator there:
Comparator<Object> maCompa = new NonCompObjectKeyComparator();
TreeMap<int[][], Integer> tempMap = new TreeMap(maCompa);
TreeMap<String[], String> sArrayMap = new TreeMap(maCompa);
int[][] matrix = {{1}};
tempMap.put(matrix, 4);
String[] sKey = {"a"};
sArrayMap.put(sKey, "anotherWierdMap");
In order to create an specific int[][] comparator, just:
public class CustomKeyComparator implements Comparator<int[][]> {
public int compare(int[][] a1, int[][] a2) {
//your logic here
return 0;
}
}
and
TreeMap<int[][], Integer> tempMap = new TreeMap(new CustomKeyComparator());
int[][] matrix = {{1}};
tempMap.put(matrix, 4);