View RSS Feed

Recent Blogs Posts

  1. Checking if a Collection Contains a Certain Element

    by , 02-18-2012 at 05:08 PM
    In collection interface, 2 methods have been implemented to check if certain elements are present in it. Two methods are as following:

    1. contains()
    2. containsAll()

    This code explains these 2 methods:
    Java Code: This is the code to explain the contains and containsAll methods
    Collection collection   = new HashSet();
    boolean containsElement = collection.contains("an element");
    
    Collection elements     = new HashSet();
    boolean containsAll     = collection.containsAll(elements);
    ...