Saturday, 1 November 2014

Java : Collection Framework : LinkedList (Check Group of Objects Exist or not)


Click here to watch in Youtube : https://www.youtube.com/watch?v=HNMN5RjwxK0

LinkedListContainsAllExample.java
import java.util.LinkedList;

/*
 * Example of containsAll(Collection<?> c) method
 */
public class LinkedListContainsAllExample
{

    public static void main(String[] args)
    {
        LinkedList<Integer> linkedList = new LinkedList<Integer>();
        linkedList.add(200);
        linkedList.add(300);
        linkedList.add(10000);
        linkedList.add(5000);
        linkedList.add(2000);

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

        LinkedList<Integer> linkedList1 = new LinkedList<Integer>();
        linkedList1.add(200);
        linkedList1.add(300);

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

        /*
         * Returns true if this collection contains all of the elements in the
         * specified collection.
         */
        boolean isExist = linkedList.containsAll(linkedList1);

        System.out
                .println("Is linkedList1 elements are there in the linkedList : "
                        + isExist + "\n");

        System.out
                .println("#########################################################"
                        + "\n");

        LinkedList<Integer> linkedList2 = new LinkedList<Integer>();
        linkedList2.add(888);
        linkedList2.add(777);

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

        isExist = linkedList.containsAll(linkedList2);

        System.out
                .println("Is linkedList2 elements are there in the linkedList : "
                        + isExist);

    }
}

Output
linkedList : [200, 300, 10000, 5000, 2000]

linkedList1 : [200, 300]

Is linkedList1 elements are there in the linkedList : true

#########################################################

linkedList2 : [888, 777]

Is linkedList2 elements are there in the linkedList : false

To Download LinkedListDemoContainsAll Project Click the below link

https://sites.google.com/site/javaee4321/java-collections/LinkedListDemoContainsAll.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