Wednesday, 31 December 2014

Java : Collection Framework : TreeSet (RetainAll)


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

TreeSetExample.java
import java.util.LinkedList;
import java.util.TreeSet;

/*
 * Example of retainAll(Collection<?> c) method.
 */
public class TreeSetExample
{
    public static void main( String[] args )
    {

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

        treeSet.add(40);
        treeSet.add(20);
        treeSet.add(30);
        treeSet.add(100);
        treeSet.add(200);

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

        LinkedList<Integer> linkedList = new LinkedList<Integer>();
        
        linkedList.add(100);
        linkedList.add(200);

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

        /*
         * Retains only the elements in this set that are contained in the
         * specified collection (optional operation). In other words, removes
         * from this set all of its elements that are not contained in the
         * specified collection.
         * 
         * If the specified collection is also a set, this operation effectively
         * modifies this set so that its value is the intersection of the two
         * sets.
         */

        boolean isRetained = treeSet.retainAll(linkedList);

        System.out.println("isRetained : " + isRetained);
        System.out.println("treeSet : " + treeSet + "\n");
    }
}
Output
treeSet : [20, 30, 40, 100, 200]

linkedList : [100, 200]

isRetained : true
treeSet : [100, 200]
To Download TreeSetDemoRetainAll Project Click the below link
https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoRetainAll.zip?attredirects=0&d=1

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : TreeSet (RemoveAll)


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

    TreeSetExample.java
    import java.util.LinkedList;
    import java.util.TreeSet;
    
    /*
     * Example of removeAll(Collection<? extends E> c) method.
     */
    public class TreeSetExample
    {
        public static void main(String[] args)
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
    
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
            treeSet.add(100);
            treeSet.add(200);
    
            System.out.println("treeSet : " + treeSet + "\n");
    
            LinkedList<Integer> linkedList = new LinkedList<Integer>();
            
            linkedList.add(100);
            linkedList.add(200);
    
            System.out.println("linkedList : " + linkedList + "\n");
    
            /*
             * Removes from this set all of its elements that are contained in the
             * specified collection
             */
    
            boolean isRemoved = treeSet.removeAll(linkedList);
    
            System.out.println("isRemoved : " + isRemoved);
            System.out.println("treeSet : " + treeSet + "\n");
        }
    }
    
    Output
    treeSet : [20, 30, 40, 100, 200]
    
    linkedList : [100, 200]
    
    isRemoved : true
    treeSet : [20, 30, 40]
    
    To Download TreeSetDemoRemoveAll Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoRemoveAll.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : TreeSet (ContainsAll)


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

    TreeSetExample.java
    import java.util.LinkedList;
    import java.util.TreeSet;
    
    /*
     * Example of containsAll(Collection<?> c) method.
     */
    public class TreeSetExample
    {
        public static void main( String[] args )
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
    
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
            treeSet.add(1000);
            treeSet.add(2000);
    
            System.out.println("treeSet : " + treeSet + "\n");
    
            LinkedList<Integer> linkedList = new LinkedList<Integer>();
            
            linkedList.add(1000);
            linkedList.add(2000);
    
            System.out.println("linkedList : " + linkedList + "\n");
    
            /*
             * Returns true if this set contains all of the elements of the
             * specified collection.
             * 
             * If the specified collection is also a set, this method returns true
             * if it is a subset of this set.
             */
    
            boolean isExist = treeSet.containsAll(linkedList);
    
            System.out.println("isExist : " + isExist);
        }
    }
    
    Output
    treeSet : [20, 30, 40, 1000, 2000]
    
    linkedList : [1000, 2000]
    
    isExist : true
    
    To Download TreeSetDemoContainsAll Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoContainsAll.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Tuesday, 30 December 2014

    Java : Collection Framework : TreeSet (Remove)


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

    TreeSetExample.java
    import java.util.TreeSet;
    
    /*
     * Example of remove(Object o) method.
     */
    public class TreeSetExample
    {
        public static void main( String[] args )
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
    
            treeSet.add(10);
            treeSet.add(50);
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
    
            System.out.println("treeSet : " + treeSet + "\n");
            /*
             * Removes the specified element from this set if it is present.
             */
    
            boolean isRemoved = treeSet.remove(50);
            System.out.println("isRemoved : " + isRemoved);
    
            System.out.println("treeSet : " + treeSet + "\n");
        }
    }
    
    Output
    treeSet : [10, 20, 30, 40, 50]
    
    isRemoved : true
    treeSet : [10, 20, 30, 40]
    
    To Download TreeSetDemoRemove Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoRemove.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : TreeSet (Constructor Accepts Collection)


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

    TreeSetExample.java
    import java.util.LinkedList;
    import java.util.TreeSet;
    
    /*
     * Example of TreeSet(Collection<? extends E> c) constructor.
     */
    public class TreeSetExample
    {
        public static void main( String[] args )
        {
            LinkedList<Integer> linkedList = new LinkedList<Integer>();
            linkedList.add(50);
            linkedList.add(30);
            linkedList.add(40);
            linkedList.add(10);
            linkedList.add(20);
    
            System.out.println("linkedList : " + linkedList + "\n");
            
            /*
             * Constructs a new tree set containing the elements in the specified
             * collection, sorted according to the natural ordering of its elements.
             * 
             * All elements inserted into the set must implement the Comparable
             * interface.
             */
            TreeSet<Integer> treeSet = new TreeSet<Integer>(linkedList);
    
            System.out.println("treeSet : " + treeSet + "\n");
    
        }
    }
    
    Output
    linkedList : [50, 30, 40, 10, 20]
    
    treeSet : [10, 20, 30, 40, 50]
    
    To Download TreeSetDemoConstAcceptsCollection Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoConstAcceptsCollection.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : TreeSet (Clone)


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

    TreeSetExample.java
    import java.util.TreeSet;
    
    /*
     * Example of clone() method.
     */
    public class TreeSetExample
    {
        public static void main( String[] args )
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
    
            treeSet.add(10);
            treeSet.add(50);
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
    
            System.out.println("treeSet : " + treeSet + "\n");
            /*
             * Returns a shallow copy of this TreeSet instance. (The elements
             * themselves are not cloned.)
             */
            TreeSet<String> clonedTreeSet = (TreeSet<String>) treeSet.clone();
    
            System.out.println("clonedTreeSet : " + clonedTreeSet);
    
        }
    }
    
    Output
    treeSet : [10, 20, 30, 40, 50]
    
    clonedTreeSet : [10, 20, 30, 40, 50]
    
    To Download TreeSetDemoClone Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoClone.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Monday, 29 December 2014

    Java : Collection Framework : TreeSet (Add Group of Objects)


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

    TreeSetExample.java
    import java.util.LinkedList;
    import java.util.TreeSet;
    
    /*
     * Example of addAll(Collection<? extends E> c) method.
     */
    public class TreeSetExample
    {
    
        public static void main(String[] args)
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
    
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
    
            System.out.println("treeSet : " + treeSet + "\n");
    
            LinkedList<Integer> linkedList = new LinkedList<Integer>();
            linkedList.add(100);
            linkedList.add(200);
    
            System.out.println("linkedList : " + linkedList + "\n");
    
            /*
             * Adds all of the elements in the linkedList to the treeSet.
             */
    
            boolean isAdded = treeSet.addAll(linkedList);
    
            System.out.println("isAdded : " + isAdded);
            System.out.println("treeSet : " + treeSet + "\n");
        }
    }
    
    Output
    treeSet : [20, 30, 40]
    
    linkedList : [100, 200]
    
    isAdded : true
    treeSet : [20, 30, 40, 100, 200]
    
    To Download TreeSetDemoAddAll Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoAddAll.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection : List Introduction - Playlist

    Java : Collection : Set Introduction - Playlist

    Java : Collection : TreeSet : Iterator - Playlist

    Java : Collection : TreeSet Sample Programs or Examples - Playlist

    Java : Collection : TreeSet - Playlist

    Java : Collection Framework : Set (Set Interface)


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

    Click the below Image to Enlarge
    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 

    Java : Collection Framework : Set (Set Interface) 


    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : LinkedHashSet (LinkedHashSet Introduction)


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

    Click the below Image to Enlarge
    Java : Collection Framework : LinkedHashSet (LinkedHasSet Introduction) 

    Java : Collection Framework : LinkedHashSet (LinkedHasSet Introduction) 

    Java : Collection Framework : LinkedHashSet (LinkedHasSet Introduction) 

    Java : Collection Framework : LinkedHashSet (LinkedHasSet Introduction) 
    See also:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : TreeSet (Iterator remove)


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

    TreeSetExample.java
    import java.util.Iterator;
    import java.util.TreeSet;
    
    /*
     * Example of Iterator remove() method.
     */
    public class TreeSetExample
    {
        public static void main(String[] args)
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
    
            treeSet.add(10);
            treeSet.add(50);
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
    
            System.out.println("treeSet : " + treeSet + "\n");
    
            /*
             * Returns an iterator over the elements in this set in ascending order.
             */
    
            Iterator<Integer> iterator = treeSet.iterator();
    
            while (iterator.hasNext())
            {
                iterator.next();
                /*
                 * Removes from the treeSet the last element that was returned by
                 * next()
                 */
                iterator.remove();
            }
    
            System.out.println("treeSet : " + treeSet + "\n");
        }
    }
    
    Output
    treeSet : [10, 20, 30, 40, 50]
    
    treeSet : []
    
    To Download TreeSetDemoIteratorRemove Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoIteratorRemove.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : TreeSet (Iterator)


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

    TreeSetExample.java
    import java.util.Iterator;
    import java.util.TreeSet;
    
    /*
     * Example of iterator() method.
     */
    public class TreeSetExample
    {
        public static void main( String[] args )
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
    
            treeSet.add(10);
            treeSet.add(50);
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
    
            System.out.println("treeSet : " + treeSet + "\n");
    
            /*
             * Returns an iterator over the elements in this set in ascending order.
             */
    
            Iterator<Integer> iterator = treeSet.iterator();
    
            /*
             * Using Iterator to get each element from the TreeSet.
             */
    
            while( iterator.hasNext() )
            {
                Integer value = iterator.next();
                System.out.println(value);
            }
        }
    }
    
    Output
    treeSet : [10, 20, 30, 40, 50]
    
    10
    20
    30
    40
    50
    
    To Download TreeSetDemoIterator Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoIterator.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : TreeSet (for-each loop)


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

    TreeSetExample.java
    import java.util.TreeSet;
    
    /*
     * Example of for-each loop.
     */
    public class TreeSetExample
    {
        public static void main( String[] args )
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
    
            treeSet.add(10);
            treeSet.add(50);
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
    
            System.out.println("treeSet : " + treeSet + "\n");
            /*
             * Using foreach loop get each element from the treeSet.
             */
    
            for( Integer value : treeSet )
            {
                System.out.println(value);
            }
        }
    }
    
    Output
    treeSet : [10, 20, 30, 40, 50]
    
    10
    20
    30
    40
    50
    
    To Download TreeSetDemoForeach Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoForeach.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : TreeSet (isEmpty)


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

    TreeSetExample.java
    import java.util.TreeSet;
    
    /*
     * Example of isEmpty() method.
     */
    public class TreeSetExample
    {
        public static void main( String[] args )
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
            
            System.out.println("treeSet : " + treeSet + "\n");
            
            /*
             * Returns true if this set contains no elements.
             */
            boolean isEmpty = treeSet.isEmpty();
            System.out.println("isEmpty :  " + isEmpty + "\n");
    
    
            treeSet.add(10);
            treeSet.add(50);
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
    
            System.out.println("treeSet : " + treeSet + "\n");
    
            /*
             * Returns true if this set contains no elements.
             */
            isEmpty = treeSet.isEmpty();
            System.out.println("isEmpty :  " + isEmpty);
        }
    }
    
    Output
    treeSet : []
    
    isEmpty :  true
    
    treeSet : [10, 20, 30, 40, 50]
    
    isEmpty :  false
    
    To Download TreeSetDemoIsEmpty Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoIsEmpty.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : TreeSet (Size)


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

    TreeSetExample.java
    import java.util.TreeSet;
    
    /*
     * Example of size() method.
     */
    public class TreeSetExample
    {
        public static void main( String[] args )
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
    
            treeSet.add(10);
            treeSet.add(50);
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
    
            System.out.println("treeSet : " + treeSet + "\n");
    
            /*
             * Returns the number of elements in this set (its cardinality).
             */
            int size = treeSet.size();
    
            System.out.println("size : " + size);
    
        }
    }
    
    Output
    treeSet : [10, 20, 30, 40, 50]
    
    size : 5
    
    To Download TreeSetDemoSize Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoSize.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java : Collection Framework : TreeSet (Clear)


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

    TreeSetExample.java
    import java.util.TreeSet;
    
    /*
     * Example of clear() method.
     */
    public class TreeSetExample
    {
        public static void main( String[] args )
        {
    
            TreeSet<Integer> treeSet = new TreeSet<Integer>();
    
            treeSet.add(10);
            treeSet.add(50);
            treeSet.add(40);
            treeSet.add(20);
            treeSet.add(30);
    
            System.out.println("treeSet : " + treeSet + "\n");
    
            /*
             * Removes all of the elements from this set. The set will be empty
             * after this call returns.
             */
            treeSet.clear();
    
            System.out.println("treeSet : " + treeSet + "\n");
    
        }
    }
    
    
    Output
    treeSet : [10, 20, 30, 40, 50]
    
    treeSet : []
    
    To Download TreeSetDemoClear Project Click the below link
    https://sites.google.com/site/javaee4321/java-collections/TreeSetDemoClear.zip?attredirects=0&d=1

    See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Google+ Followers

    Google+ Badge