Wednesday, 31 December 2014

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
  • No comments:

    Post a Comment