Try using some class that implements SortedSet interface such as TreeSet.

Leandro Oliveira
Ranch Hand

Joined: Nov 07, 2002
Posts: 298

posted Mar 24, 2003 07:27:00

0

Example: Set s=new TreeSet(); s.add("leandro"); s.add("jose"); s.add("pedro"); s.add("carlos"); s.add("alex"); Iterator i=s.iterator(); while(i.hasNext()){ System.out.println(i.next()); } this will print all the elements in the natural order, I added string elements, String class implements java.lang.Comparable, if your object does not implements Comparable, you can create a Comparator, just implementing java.util.Comparator. Hope it helps!