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:
import java.util.*;
public class GFG {
public static void main(String[] argv)
{
AbstractSequentialList<String>
arrlist1 = new LinkedList<String>();
arrlist1.add( "A" );
arrlist1.add( "B" );
arrlist1.add( "C" );
arrlist1.add( "D" );
arrlist1.add( "E" );
System.out.println( "First AbstractSequentialListlist: "
+ arrlist1);
AbstractSequentialList<String>
arrlist2 = new LinkedList<String>();
arrlist2.add( "A" );
arrlist2.add( "B" );
arrlist2.add( "C" );
arrlist2.add( "D" );
arrlist2.add( "E" );
System.out.println( "Second AbstractSequentialList: "
+ arrlist2);
boolean value
= arrlist1.equals(arrlist2);
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:
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
{
AbstractSequentialList<Integer>
arrlist1 = new LinkedList<Integer>();
arrlist1.add( 10 );
arrlist1.add( 20 );
arrlist1.add( 30 );
arrlist1.add( 40 );
arrlist1.add( 50 );
System.out.println( "First AbstractSequentialListlist: "
+ arrlist1);
AbstractSequentialList<Integer>
arrlist2 = new LinkedList<Integer>();
arrlist2.add( 10 );
arrlist2.add( 20 );
arrlist2.add( 30 );
System.out.println( "Second AbstractSequentialList: "
+ arrlist2);
boolean value = arrlist1.equals(arrlist2);
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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
24 Dec, 2018
Like Article
Save Article