Answers for "TreeMap lowerEntry(K key) method in java"

2

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);
      }
   }
}
Posted by: Guest on October-28-2020
2

TreeMap lowerEntry(K key) method in java

import java.util.TreeMap;
public class TreeMapLowerEntryMethodExample
{
   public static void main(String[] args)
   {
      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");
      // get lower entry
      System.out.println("Check lower entry in given TreeMap");
      System.out.println("Value is: "+ tm.lowerEntry(5));
   }
}
Posted by: Guest on October-28-2020
2

TreeMap lowerKey(K key) method in java

import java.util.TreeMap;
public class TreeMapLowerKeyMethodExample
{
   public static void main(String[] args)
   {
      TreeMap<Integer, String> tm = new TreeMap<Integer, String>();
      tm.put(8, "mango");
      tm.put(5, "apple");
      tm.put(3, "watermelon");
      tm.put(7, "pineapple");
      tm.put(6, "orange");
      tm.put(9, "grapes");
      System.out.println("TreeMap: " + tm.toString());
      // here 10 is not available it returns 9
      System.out.print("Lower Key Entry of Element 10 is: ");
      System.out.println(tm.lowerKey(10));
      System.out.print("Lower Key Entry of Element 5 is: ");
      System.out.println(tm.lowerKey(5));
   }
}
Posted by: Guest on October-28-2020

Code answers related to "TreeMap lowerEntry(K key) method in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language