Still about sorting TreeMap

Why this is not working?

I want to order by the first index of the value:

Map map =new TreeMap( ) ;

map.put("115.393.028-57",new Object[]{"FRANK","VALLEY"} ) ;

map.put("105.393.028-57",new Object[]{"JOHN","SMITH"} ) ;

map.put("112.393.028-57",new Object[]{"KYLE","BREAT"} ) ;

Set set =new TreeSet(new Comparator(){

publicint compare( Object o1, Object o2 ){

Map.Entry e1 = ( Map.Entry ) o1;

Map.Entry e2 = ( Map.Entry ) o2;

Object[] d1 = ( Object[] ) e1.getValue( ) ;

Object[] d2 = ( Object[] ) e2.getValue( ) ;

String name1 = (String)d1[0];

String name2 = (String)d2[0];

return name1.compareTo( name2 ) ;

}

}) ;

set.addAll( map.entrySet( )) ;

for ( Iterator iter = set.iterator( ) ; iter.hasNext( ) ; ){

Map.Entry entry = ( Map.Entry ) iter.next( ) ;

System.out.println( entry.getKey( ) +" = " + entry.getValue()) ;

}

[1861 byte] By [Franziska] at [2007-11-26 18:28:19]
# 1
1. Don't start new thread about the same topic.2. It works fine for me. If you want it to sort by last name instead of first you will need to modify the code.
zadoka at 2007-7-9 6:02:30 > top of Java-index,Java Essentials,Java Programming...
# 2
Not that I look at your code closer, why aren't you just creating a Person class that implements comparable and using it in a sorted set. It would much more readable, simple, and OO friendly.
zadoka at 2007-7-9 6:02:30 > top of Java-index,Java Essentials,Java Programming...