TreeMap descendingMap() method in java

import java.util.NavigableMap;
import java.util.TreeMap;
public class TreeMapDescendingMapMethodExample
{
   public static void main(String[] args)
   {
      TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
      tm.put(93, "blue");
      tm.put(26, "violet");
      tm.put(63, "red");
      tm.put(53, "green");
      tm.put(96, "five");
      // put values in NavigableMap
      NavigableMap nm = tm.descendingMap();
      System.out.println("TreeMap values using descendingMap() method: ");
      System.out.println("NavigableMap values: " + nm);
   }
}

4.75
4

                                    import java.util.NavigableSet;
import java.util.TreeMap;
public class TreeMapDescendingKeySetMethodExample
{
   public static void main(String[] args)
   {
      TreeMap&lt;Integer, String&gt; tm = new TreeMap&lt;Integer, String&gt;();
      tm.put(63, &quot;banana&quot;);
      tm.put(56, &quot;watermelon&quot;);
      tm.put(35, &quot;orange&quot;);
      tm.put(83, &quot;apple&quot;);
      tm.put(65, &quot;pineapple&quot;);
      // put values in NavigableSet
      NavigableSet ns = tm.descendingKeySet();
      System.out.println(&quot;TreeMap values using descendingKeySet() method: &quot;);
      System.out.println(&quot;NavigableSet values: &quot; + ns);
   }
}

4.75 (4 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