Friday, 9 January 2015

Java : Collection Framework : TreeSet (null)

Click here to watch in Youtube :
import java.util.TreeSet;

 * TreeSet doesn't allow null and throw java.lang.NullPointerException
 * when you will insert null into TreeSet. 
 * Since TreeSet uses compareTo() method of respective elements to compare them  
 * which throws NullPointerException while comparing with null.
public class TreeSetExample
    public static void main( String[] args )

        TreeSet<String> treeSet = new TreeSet<String>();

        System.out.println("\ntreeSet : " + treeSet);

Exception in thread "main" java.lang.NullPointerException
    at java.util.TreeMap.put(Unknown Source)
    at java.util.TreeSet.add(Unknown Source)
    at TreeSetExample.main(
To Download TreeSetDemoNull Project Click the below link

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge