Skip to content

Instantly share code, notes, and snippets.

@gaul
Created July 30, 2013 02:46
Show Gist options
  • Save gaul/6109765 to your computer and use it in GitHub Desktop.
Save gaul/6109765 to your computer and use it in GitHub Desktop.
Demonstrate a case-insensitive map using Treemap and a comparator.
import java.util.TreeMap;
public class CaseInsensitiveMap {
public static void main(String[] args) {
TreeMap<String, String> map = new TreeMap<String, String>(
String.CASE_INSENSITIVE_ORDER);
assert map.isEmpty();
map.put("a", "b");
assert map.size() == 1;
assert map.get("a").equals("b");
assert map.get("A").equals("b");
map.put("A", "c");
assert map.size() == 1;
assert map.get("a").equals("c");
assert map.get("A").equals("c");
map.put("b", "b");
assert map.size() == 2;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment