AbstractSequentialList equals() method in Java with Example

The equals() method of java.util.AbstractSequentialList class is used to check if this AbstractSequentialList object is equal to the object passed as the parameter. This method returns a boolean value stating the same.

Syntax:

public boolean equals(Object o)

Parameters: This method takes the object o as a parameter to be compared for equality with this list.



Returns Value: This method returns true if the specified object is equal to this list.

Below are the examples to illustrate the equals() method.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate equals()
// method of AbstractSequentialList
  
import java.util.*;
  
public class GFG {
    public static void main(String[] argv)
    {
  
        // Creating object of AbstractSequentialList<String>
        AbstractSequentialList<String>
            arrlist1 = new LinkedList<String>();
  
        // Populating arrlist1
        arrlist1.add("A");
        arrlist1.add("B");
        arrlist1.add("C");
        arrlist1.add("D");
        arrlist1.add("E");
  
        // print arrlist1
        System.out.println("First AbstractSequentialListlist: "
                           + arrlist1);
  
        // Creating another object of AbstractSequentialList<String>
        AbstractSequentialList<String>
            arrlist2 = new LinkedList<String>();
  
        // Populating arrlist2
        arrlist2.add("A");
        arrlist2.add("B");
        arrlist2.add("C");
        arrlist2.add("D");
        arrlist2.add("E");
  
        // print arrlist2
        System.out.println("Second AbstractSequentialList: "
                           + arrlist2);
  
        // comparing first AbstractSequentialList to another
        // using equals() method
        boolean value
            = arrlist1.equals(arrlist2);
  
        // print the value
        System.out.println("Are both list equal: "
                           + value);
    }
}

chevron_right


Output:

First AbstractSequentialListlist: [A, B, C, D, E]
Second AbstractSequentialList: [A, B, C, D, E]
Are both list equal: true

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to demonstrate equals()
// method of AbstractSequentialList
  
import java.util.*;
  
public class GFG1 {
    public static void main(String[] argv)
    {
  
        // Creating object of AbstractSequentialList
        AbstractSequentialList<Integer>
            arrlist1 = new LinkedList<Integer>();
  
        // Populating arrlist1
        arrlist1.add(10);
        arrlist1.add(20);
        arrlist1.add(30);
        arrlist1.add(40);
        arrlist1.add(50);
  
        // print arrlist1
        System.out.println("First AbstractSequentialListlist: "
                           + arrlist1);
  
        // Creating another object of AbstractSequentialList
        AbstractSequentialList<Integer>
            arrlist2 = new LinkedList<Integer>();
  
        // Populating arrlist2
        arrlist2.add(10);
        arrlist2.add(20);
        arrlist2.add(30);
  
        // print arrlist2
        System.out.println("Second AbstractSequentialList: "
                           + arrlist2);
  
        // comparing first AbstractSequentialList to another
        // using equals() method
        boolean value = arrlist1.equals(arrlist2);
  
        // print the value
        System.out.println("Are both list equal: "
                           + value);
    }
}

chevron_right


Output:

First AbstractSequentialListlist: [10, 20, 30, 40, 50]
Second AbstractSequentialList: [10, 20, 30]
Are both list equal: 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.