treeset descendingset 28 29 method in java

Solutions on MaxInterview for treeset descendingset 28 29 method in java by the best coders in the world

showing results for - "treeset descendingset 28 29 method in java"
Johann
16 Feb 2018
1import java.util.Iterator;
2import java.util.NavigableSet;
3import java.util.TreeSet;
4public class TreeSetDescendingSetMethodExample
5{
6   public static void main(String[] args)
7   {
8      try
9      {
10         TreeSet<String> ts = new TreeSet<String>();
11         ts.add("Apple");
12         ts.add("Banana");
13         ts.add("Cherry");
14         ts.add("Dragon Fruit");
15         System.out.println("TreeSet: " + ts);
16         // reverse order view of element using descendingSet() method
17         NavigableSet<String> ns = ts.descendingSet();
18         Iterator<String> iterate = ns.iterator();
19         System.out.println("Values using descendingSet() method: ");
20         while(iterate.hasNext())
21         {
22            System.out.println(iterate.next());
23         }
24      }
25      catch(NullPointerException ex)
26      {
27         System.out.println("Exception: " + ex);
28      }
29   }
30}
Federico
20 Apr 2018
1import java.util.Iterator;
2import java.util.TreeSet;
3public class TreeSetDescendingIteratorMethodExample
4{
5   public static void main(String[] args)
6   {
7      try
8      {
9         TreeSet<Integer> ts = new TreeSet<Integer>();
10         ts.add(50);
11         ts.add(60);
12         ts.add(70);
13         ts.add(80);
14         System.out.println("TreeSet: " + ts);
15         // create descending iterator using descendingIterator() method
16         Iterator<Integer> iterate = ts.descendingIterator();
17         System.out.println("Values using descendingIterator() method: ");
18         while(iterate.hasNext())
19         {
20            System.out.println(iterate.next());
21         }
22      }
23      catch(NullPointerException ex)
24      {
25         System.out.println("Exception: " + ex);
26      }
27   }
28}
Simon
13 May 2017
1TreeSet descendingIterator() method for String value.
2import java.util.Iterator;
3import java.util.TreeSet;
4public class TreeSetDescendingIteratorMethodExample
5{
6   public static void main(String[] args)
7   {
8      try
9      {
10         TreeSet<String> ts = new TreeSet<String>();
11         ts.add("Ajay");
12         ts.add("Bharat");
13         ts.add("Chetan");
14         ts.add("Dinesh");
15         System.out.println("TreeSet: " + ts);
16         // create descending iterator using descendingIterator() method
17         Iterator<String> iterate = ts.descendingIterator();
18         System.out.println("Values using descendingIterator() method: ");
19         while(iterate.hasNext())
20         {
21            System.out.println(iterate.next());
22         }
23      }
24      catch(NullPointerException ex)
25      {
26         System.out.println("Exception: " + ex);
27      }
28   }
29}