treeset higher 28 29 method in java

Solutions on MaxInterview for treeset higher 28 29 method in java by the best coders in the world

showing results for - "treeset higher 28 29 method in java"
Jerónimo
09 Nov 2016
1import java.util.TreeSet;
2public class TreeSetHigherMethodExample
3{
4   public static void main(String[] args)
5   {
6      TreeSet<Integer> ts = new TreeSet<Integer>();
7      ts.add(9);
8      ts.add(4);
9      ts.add(6);
10      ts.add(2);
11      ts.add(10);
12      ts.add(3);
13      System.out.println(ts.higher(9));
14   }
15}
Giulia
23 Jul 2016
1TreeSet higher() method for NullPointerException.
2import java.util.TreeSet;
3public class TreeSetHigherMethodExample
4{
5   public static void main(String[] args)
6   {
7      TreeSet<Integer> ts = new TreeSet<Integer>();
8      ts.add(9);
9      ts.add(4);
10      ts.add(6);
11      ts.add(2);
12      ts.add(10);
13      ts.add(3);
14      // pass null to method
15      try
16      {
17         System.out.println(ts.higher(null));
18      }
19      catch(Exception ex)
20      {
21         System.out.println(ex);
22      }
23   }
24}
Hanna
05 Jan 2021
1TreeSet higher() method for ClassCastException.
2import java.util.ArrayList;
3import java.util.LinkedList;
4import java.util.List;
5import java.util.TreeSet;
6public class TreeSetHigherMethodExample
7{
8   public static void main(String[] args)
9   {
10      TreeSet<List> ts = new TreeSet<List>();
11      List<Integer> li1 = new LinkedList<Integer>();
12      try
13      {
14         li1.add(2);
15         li1.add(4);
16         ts.add(li1);
17         List<Integer> li2 = new LinkedList<Integer>();
18         li2.add(6);
19         li2.add(8);
20         List<Integer> li3 = new ArrayList<Integer>();
21         li2.add(10);
22         li2.add(12);
23      }
24      catch(Exception ex)
25      {
26         System.out.println(ex);
27      }
28   }
29}