Wednesday 12 June 2013

Map with Case-Insensitive Keys

Below is the easy way, for case-insensitive key searches in a Map.


Map<String, String[]> treemap = new TreeMap<String, String[]>(String.CASE_INSENSITIVE_ORDER);

treemap.put("name1","value1");
treemap.put("NAME2","value2");
 
treemap.get("NAME1")   //you get "value1"
treemap.get("naME2")   //you get "value2"



[WARNING]  treemap.get(null) throws NulllPointerException in certain versions of Java