import java.util.*;
public class ABC {
public static void main(String[] args)
{
HashSet h=new HashSet();
h.add(1); /*insert any desired value*/
h.add(12);
h.add(13);
h.add(14);
h.add(16);
h.add(67);
TreeSet t= new TreeSet(h);
TreeSet t1=new TreeSet();
System.out.println(t);
Iterator i=t.iterator();
System.out.println("In ascending Order--------");
while(i.hasNext())
{ System.out.print(i.next()+ " ");}
System.out.println();
System.out.println("In descending Order---------");
t1=(TreeSet) t.descendingSet();
Iterator i1=t1.iterator();
while(i1.hasNext()){System.out.print(i1.next() +" "); }
}
}
No comments:
Post a Comment