Oliver
Posts: 12
Nickname: lazycat
Registered: Dec, 2002
|
|
Re: How can i order in decending order Using hash set
|
Posted: Dec 19, 2002 7:54 AM
|
|
import java.util.*;
class DescendHashSet { public static void main(String [] args){ String [] items = {"3", "1", "4", "1", "5","9"};
DescendComp descendSort = new DescendComp();
Set ascendSet = new TreeSet(); Set descendSet = new TreeSet(descendSort);
for(int i = 0; i < items.length; i++){ ascendSet.add(new Integer(items)); descendSet.add(new Integer(items)); } System.out.println(ascendSet); System.out.println(descendSet); } } class DescendComp implements Comparator { public int compare(Object str1, Object str2){ Integer tmp1 = (Integer)str1; Integer tmp2 = (Integer)str2; return -(tmp1.compareTo(tmp2)); } }
|
|