Is there a good way to have a Map<String, ?> get and put ignoring case?

Joshua picture Joshua · Oct 17, 2008 · Viewed 23.7k times · Source

Is there a good way to have a Map<String, ?> get and put ignoring case?

Answer

volley picture volley · Dec 9, 2009

TreeMap extends Map and supports custom comparators.

String provides a default case insensitive comparator.

So:

final Map<String, ...> map = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);

The comparator does not take locale into account. Read more about it in its JavaDoc.