Code example for TreeMap

Methods: put, subMap

0
        tree.remove(tree.lastKey());
        assertEquals(submap, tree);
    } 
 
    public void testname() throws Exception { 
        TreeMap nullTree = new TreeMap(new Comparator() {
            public int compare(Object o1, Object o2) {
                if (o1 == null) {
                    return o2 == null ? 0 : -1;
                } 
                return ((String) o1).compareTo((String) o2);
            } 
        }); 
        nullTree.put(new String("One"), 1);
        nullTree.put(new String("Two"), 2);
        nullTree.put(new String("Three"), 3);
        nullTree.put(new String("Four"), 4);
        nullTree.put(null, 0);
        nullTree.subMap(null, "two").size();
    } 
 
}