Monday, 29 December 2014

Java : Collection Framework : TreeSet (Add Object)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=IzBrL_EYt3s&list=UUhwKlOVR041tngjerWxVccw

TreeSetExample.java
import java.util.TreeSet;

/*
 * Example of add(E e) method.
 */
public class TreeSetExample
{
    public static void main( String[] args )
    {

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

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

        /*
         * Adds the specified element to this set if it is not already present.
         * 
         * If this set already contains the element, the call leaves the set
         * unchanged and returns false.
         */
        boolean isAdded = treeSet.add(10);

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

        isAdded = treeSet.add(10);

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

    }
}

Output
treeSet : []

isAdded : true
treeSet: [10]

isAdded : false
treeSet: [10]
To Download TreeSetDemoAdd Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoAdd.zip?attredirects=0&d=1

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