java treeset floor code example
Example 1: TreeSet floor() method in java
import java.util.TreeSet;
public class TreeSetFloorMethodExample
{
public static void main(String[] args)
{
try
{
TreeSet<Integer> ts = new TreeSet<Integer>();
ts.add(50);
ts.add(60);
ts.add(70);
ts.add(80);
System.out.println("Given TreeSet: " + ts);
int value = ts.floor(65);
System.out.println("Floor value for 65 is : " + value);
}
catch(NullPointerException ex)
{
System.out.println("Exception: " + ex);
}
}
}
Example 2: TreeSet floor() method in java
floor() method for NullPointerException.
import java.util.TreeSet;
public class TreeSetFloorMethodExample
{
public static void main(String[] args)
{
try
{
TreeSet<Integer> ts = new TreeSet<Integer>();
ts.add(50);
ts.add(60);
ts.add(70);
ts.add(80);
System.out.println("Given TreeSet: " + ts);
System.out.println("Get floor value for null: ");
int value = ts.floor(null);
System.out.println("Floor value for 65: " + value);
}
catch(NullPointerException ex)
{
System.out.println("Exception: " + ex);
}
}
}