I have Map in Java:
Map<Pair<String, String>, MyClass> myMap;
I need the Pair to NOT be case-sensitive. The solution in case of regular string key is simple:
TreeMap<String, MyClass> myMap= new TreeMap(String.CASE_INSENSITIVE_ORDER);
But, what about case of strings-pair key?
I need to compare first (left) value case-sensitive and then second (right) case-insensitive.
If you wanted to use
TreeMap, you can write a customComparatoras mentioned in the comments by Federico klez Culloca. See also the other answers on how to do this. However,TreeMapshould only be used if you really want your entries to by sorted by key.If you don't need sorting, you can also create a custom key class with
hashCodeandequalsmethods and use aHashMap:If it's ok if the
Strings are stored in lowercase form, you could do that as well:and then use a