AbstractSequentialList contains() method in Java with Example

The contains() method of Java AbstractSequentialList is used to check whether an element is present in a Collection or not. It takes the element as a parameter and returns True if the element is present in the collection.

Syntax:

public boolean contains(Object element)

Parameters: The parameter element is of type Collection. This parameter refers to the element whose occurrence is needed to be checked in the collection.

Return Value: The method returns a boolean value. It returns True if the element is present in the Collection otherwise it returns False.

Below programs illustrate the AbstractSequentialList.contains() method:

Program 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to illustrate
// AbstractSequentialList.contains()
  
import java.util.*;
  
public class GFG {
    public static void main(String args[])
    {
  
        // Creating an empty Collection
        AbstractSequentialList<String>
            abs = new LinkedList<String>();
  
        // Use add() method to add
        // elements in the collection
        abs.add("Geeks");
        abs.add("for");
        abs.add("Geeks");
        abs.add("10");
        abs.add("20");
  
        // Displaying the collection
        System.out.println("AbstractSequentialList: "
                           + abs);
  
        // Check if the collection contains "Hello"
        System.out.println("\nDoes the Collection"
                           + " contains 'Hello': "
                           + abs.contains("Hello"));
  
        // Check if the Collection contains "20"
        System.out.println("Does the collection"
                           + " contains '20': "
                           + abs.contains("20"));
  
        // Check if the Collection contains "Geeks"
        System.out.println("Does the Collection"
                           + " contains 'Geeks': "
                           + abs.contains("Geeks"));
    }
}

chevron_right


Output:

AbstractSequentialList: [Geeks, for, Geeks, 10, 20]

Does the Collection contains 'Hello': false
Does the collection contains '20': true
Does the Collection contains 'Geeks': true

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java code to illustrate
// AbstractSequentialList.contains()
  
import java.util.*;
  
public class GFG {
    public static void main(String args[])
    {
  
        // Creating an empty Collection
        AbstractSequentialList<Integer>
            abs = new LinkedList<Integer>();
  
        // Use add() method to add
        // elements in the collection
        abs.add(10);
        abs.add(20);
        abs.add(30);
        abs.add(40);
        abs.add(50);
  
        // Displaying the collection
        System.out.println("AbstractSequentialList:"
                           + abs);
  
        // Check if the collection contains 10
        System.out.println("\nDoes the Collection "
                           + "contains '10': "
                           + abs.contains(10));
  
        // Check if the collection contains 50
        System.out.println("\nDoes the Collection"
                           + " contains '50': "
                           + abs.contains(50));
  
        // Check if the Collection contains 100
        System.out.println("Does the collection"
                           + " contains '100': "
                           + abs.contains(100));
    }
}

chevron_right


Output:

AbstractSequentialList:[10, 20, 30, 40, 50]

Does the Collection contains '10': true

Does the Collection contains '50': true
Does the collection contains '100': false


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.