LinkedList boolean containsAll(Collection> c) method example Program
By candid | Posted :
Jun 30, 2015
| Updated :
Jun 30, 2015
Returns true if this list contains all of the elements of the specified collection.
Program
package com.candidjava;
import java.util.LinkedList;
import java.util.List;
/*
* @author : Mohan
* @description : containAll() method find does LinkedList contains all list elements or not.
*
*/
public class LinkedListContainAll {
public static void main(String[] args) {
LinkedList list = new LinkedList();
list.add("karthi");
list.add("mohan");
list.add("anand");
list.add("hari");
list.add("kamal");
System.out.println(list);
List<String> lt = new LinkedList<String>();
lt.add("Sekar");
lt.add("hari");
System.out.println(lt.containsAll(list));
}
}
Output
[karthi, mohan, anand, hari, kamal]
false
Explanation
boolean containsAll(Collection<?> c)
Returns true if this list contains all of the elements of the specified collection.
Specified by:
containsAll in interface Collection<E>
Parameters:
c - collection to be checked for containment in this list
Returns:
true if this list contains all of the elements of the specified collection
Throws:
ClassCastException - if the types of one or more elements in the specified collection are incompatible with this list (optional)
NullPointerException - if the specified collection contains one or more null elements and this list does not permit null elements (optional), or if the specified collection is null