TreeSet higher() method in java

TreeSet higher() method for NullPointerException.
import java.util.TreeSet;
public class TreeSetHigherMethodExample
{
   public static void main(String[] args)
   {
      TreeSet<Integer> ts = new TreeSet<Integer>();
      ts.add(9);
      ts.add(4);
      ts.add(6);
      ts.add(2);
      ts.add(10);
      ts.add(3);
      // pass null to method
      try
      {
         System.out.println(ts.higher(null));
      }
      catch(Exception ex)
      {
         System.out.println(ex);
      }
   }
}

3.56
10
JChris 95 points

                                    TreeSet higher() method for ClassCastException.
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.TreeSet;
public class TreeSetHigherMethodExample
{
   public static void main(String[] args)
   {
      TreeSet&lt;List&gt; ts = new TreeSet&lt;List&gt;();
      List&lt;Integer&gt; li1 = new LinkedList&lt;Integer&gt;();
      try
      {
         li1.add(2);
         li1.add(4);
         ts.add(li1);
         List&lt;Integer&gt; li2 = new LinkedList&lt;Integer&gt;();
         li2.add(6);
         li2.add(8);
         List&lt;Integer&gt; li3 = new ArrayList&lt;Integer&gt;();
         li2.add(10);
         li2.add(12);
      }
      catch(Exception ex)
      {
         System.out.println(ex);
      }
   }
}

3.56 (9 Votes)
0
5
1
Mason M2J 85 points

                                    import java.util.TreeSet;
public class TreeSetHigherMethodExample
{
   public static void main(String[] args)
   {
      TreeSet&lt;Integer&gt; ts = new TreeSet&lt;Integer&gt;();
      ts.add(9);
      ts.add(4);
      ts.add(6);
      ts.add(2);
      ts.add(10);
      ts.add(3);
      System.out.println(ts.higher(9));
   }
}

5 (1 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