Created
July 30, 2013 02:46
-
-
Save gaul/6109765 to your computer and use it in GitHub Desktop.
Demonstrate a case-insensitive map using Treemap and a comparator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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