Friday, 10 October 2014

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
























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

ArrayListContainsAllExample.java
import java.util.ArrayList;

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

    public static void main( String[] args )
    {
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("Ram");
        arrayList.add("Dave");
        arrayList.add("Peter");
        arrayList.add("Julia");
        arrayList.add("Akram");

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

        ArrayList<String> arrayList1 = new ArrayList<String>();
        arrayList1.add("Ram");
        arrayList1.add("Julia");

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

        boolean isExist=arrayList.containsAll(arrayList1);
        
        System.out.println("Is ArrayList1 elements are there in ArrayList : "
                + isExist + "\n");

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

        ArrayList<String> arrayList2 = new ArrayList<String>();
        arrayList2.add("Ram");
        arrayList2.add("Raju");

        System.out.println("ArrayList2 : " + arrayList2 + "\n");
        
        isExist =arrayList.containsAll(arrayList2);
        
        System.out.println("Is ArrayList2 elements are there in ArrayList : "
                +isExist );

    }
}

Output
ArrayList : [Ram, Dave, Peter, Julia, Akram]

ArrayList1 : [Ram, Julia]

Is ArrayList1 elements are there in ArrayList : true

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

ArrayList2 : [Ram, Raju]

Is ArrayList2 elements are there in ArrayList : false

To Download ArrayListDemoContainsAll Project Click the below link

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