TreeMap lowerEntry(K key) method in java

import java.util.Map;
import java.util.TreeMap;
public class TreeMapLowerEntryMethodExample
{
   public static void main(String[] args)
   {
      try
      {
         TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
         tm.put(7, "red");
         tm.put(3, "green");
         tm.put(6, "violet");
         tm.put(5, "blue");
         tm.put(4, "yellow");
         System.out.println("Given TreeMap: " + tm);
         // get lowerEntry value for null using lowerEntry() method
         System.out.println("Get lowerEntry value for value null: ");
         Map.Entry<Integer, String> value = tm.lowerEntry(null);
         System.out.println("Value is: " + value);
      }
      catch(NullPointerException ex)
      {
         System.out.println("Exception : " + ex);
      }
   }
}

3.43
7

                                    import java.util.TreeMap;
public class TreeMapLowerEntryMethodExample
{
   public static void main(String[] args)
   {
      TreeMap&lt;Integer, String&gt; tm = new TreeMap&lt;Integer, String&gt;();
      tm.put(7, &quot;red&quot;);
      tm.put(3, &quot;green&quot;);
      tm.put(6, &quot;violet&quot;);
      tm.put(5, &quot;blue&quot;);
      tm.put(4, &quot;yellow&quot;);
      // get lower entry
      System.out.println(&quot;Check lower entry in given TreeMap&quot;);
      System.out.println(&quot;Value is: &quot;+ tm.lowerEntry(5));
   }
}

3.43 (7 Votes)
0
3.67
3
Hrishioa 80 points

                                    import java.util.TreeMap;
public class TreeMapLowerKeyMethodExample
{
   public static void main(String[] args)
   {
      TreeMap&lt;Integer, String&gt; tm = new TreeMap&lt;Integer, String&gt;();
      tm.put(8, &quot;mango&quot;);
      tm.put(5, &quot;apple&quot;);
      tm.put(3, &quot;watermelon&quot;);
      tm.put(7, &quot;pineapple&quot;);
      tm.put(6, &quot;orange&quot;);
      tm.put(9, &quot;grapes&quot;);
      System.out.println(&quot;TreeMap: &quot; + tm.toString());
      // here 10 is not available it returns 9
      System.out.print(&quot;Lower Key Entry of Element 10 is: &quot;);
      System.out.println(tm.lowerKey(10));
      System.out.print(&quot;Lower Key Entry of Element 5 is: &quot;);
      System.out.println(tm.lowerKey(5));
   }
}

3.67 (3 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