TreeSet descendingSet() method in java

TreeSet descendingIterator() method for String value.
import java.util.Iterator;
import java.util.TreeSet;
public class TreeSetDescendingIteratorMethodExample
{
   public static void main(String[] args)
   {
      try
      {
         TreeSet<String> ts = new TreeSet<String>();
         ts.add("Ajay");
         ts.add("Bharat");
         ts.add("Chetan");
         ts.add("Dinesh");
         System.out.println("TreeSet: " + ts);
         // create descending iterator using descendingIterator() method
         Iterator<String> iterate = ts.descendingIterator();
         System.out.println("Values using descendingIterator() method: ");
         while(iterate.hasNext())
         {
            System.out.println(iterate.next());
         }
      }
      catch(NullPointerException ex)
      {
         System.out.println("Exception: " + ex);
      }
   }
}

4.17
9
SigTerm 80 points

                                    import java.util.Iterator;
import java.util.NavigableSet;
import java.util.TreeSet;
public class TreeSetDescendingSetMethodExample
{
   public static void main(String[] args)
   {
      try
      {
         TreeSet&lt;String&gt; ts = new TreeSet&lt;String&gt;();
         ts.add(&quot;Apple&quot;);
         ts.add(&quot;Banana&quot;);
         ts.add(&quot;Cherry&quot;);
         ts.add(&quot;Dragon Fruit&quot;);
         System.out.println(&quot;TreeSet: &quot; + ts);
         // reverse order view of element using descendingSet() method
         NavigableSet&lt;String&gt; ns = ts.descendingSet();
         Iterator&lt;String&gt; iterate = ns.iterator();
         System.out.println(&quot;Values using descendingSet() method: &quot;);
         while(iterate.hasNext())
         {
            System.out.println(iterate.next());
         }
      }
      catch(NullPointerException ex)
      {
         System.out.println(&quot;Exception: &quot; + ex);
      }
   }
}

4.17 (6 Votes)
0
4.4
5
Harley 120 points

                                    import java.util.Iterator;
import java.util.TreeSet;
public class TreeSetDescendingIteratorMethodExample
{
   public static void main(String[] args)
   {
      try
      {
         TreeSet&lt;Integer&gt; ts = new TreeSet&lt;Integer&gt;();
         ts.add(50);
         ts.add(60);
         ts.add(70);
         ts.add(80);
         System.out.println(&quot;TreeSet: &quot; + ts);
         // create descending iterator using descendingIterator() method
         Iterator&lt;Integer&gt; iterate = ts.descendingIterator();
         System.out.println(&quot;Values using descendingIterator() method: &quot;);
         while(iterate.hasNext())
         {
            System.out.println(iterate.next());
         }
      }
      catch(NullPointerException ex)
      {
         System.out.println(&quot;Exception: &quot; + ex);
      }
   }
}

4.4 (5 Votes)
0
Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source