Export (0) Print
Expand All

List.containsAll Method

Visual Studio 2005

Checks if a List object contains all the elements of a collection.

Package: java.util

Assembly: vjslib (in vjslib.dll)


public abstract boolean containsAll(
    java.util.Collection c);

Parameters

c

The name of the collection.

true if all the elements were found; false otherwise.

In this example, you create a linked list object, lList, and add some elements to it. Then you create another linked list object, lList1, and copy lList to it. Testing lList1 to see if it contains all the elements of lList gives the result true.

// list-contAll1.jsl
// List.containsAll example

import java.util.*;

public class MyClass
{
    public static void main(String[] args)
    {
        // Create a linked list object:
        LinkedList lList =  new LinkedList();

        // Add some elements:
        lList.add("My Node");
        lList.add("Your Node");
        lList.add(null);
        lList.add(new Integer(55));

        // Create a new list lList1:
        LinkedList lList1 =  new LinkedList();

        // Add all the elements of lList to lList1:
        lList1.addAll(lList);

        // Confirm that the elements of IList exist in IList1:
        if(lList1.containsAll(lList))
            System.out.println(
                  "All the elements exist in the new list.");
    }
}

/*
Output:
All the elements exist in the new list.
*/

Community Additions

ADD
Show:
© 2014 Microsoft