Monday, November 18, 2024
Google search engine
HomeLanguagesJavaAbstractSequentialList equals() method in Java with Example

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:




// 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);
    }
}


Output:

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

Example 2:




// 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);
    }
}


Output:

First AbstractSequentialListlist: [10, 20, 30, 40, 50]
Second AbstractSequentialList: [10, 20, 30]
Are both list equal: false
Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments