ConcurrentLinkedDeque equals() method in Java with Example
The equals() method of java.util.ConcurrentLinkedDeque class is used to compare the specified object with this ConcurrentLinkedDeque for equality. Returns true if and only if the specified object is also a ConcurrentLinkedDeque, both ConcurrentLinkedDeques have the same size, and all corresponding pairs of elements in the two ConcurrentLinkedDeques are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two ConcurrentLinkedDeques are defined to be equal if they contain the same elements in the same order.
Syntax:
public boolean equals(Object o)
Parameters: This method takes the object o as a parameter to be compared for equality with this ConcurrentLinkedDeque.
Return Value: This method returns true if the specified object is equal to this ConcurrentLinkedDeque.
Below programs illustrate the ConcurrentLinkedDeque.equals() method:
Program 1:
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
ConcurrentLinkedDeque<Integer> CLD1
= new ConcurrentLinkedDeque<Integer>();
CLD1.add( 7855642 );
CLD1.add( 35658786 );
CLD1.add( 5278367 );
CLD1.add( 74381793 );
System.out.println( "Linked Blocking Deque 1: " + CLD1);
ConcurrentLinkedDeque<String> CLD2
= new ConcurrentLinkedDeque<String>();
CLD2.add( "1" );
CLD2.add( "2" );
CLD2.add( "3" );
CLD2.add( "4" );
System.out.println( "Linked Blocking Deque 2: " + CLD2);
System.out.println( "Are both Linked Blocking Deque equal: "
+ CLD1.equals(CLD2));
}
}
|
Output:
Linked Blocking Deque 1: [7855642, 35658786, 5278367, 74381793]
Linked Blocking Deque 2: [1, 2, 3, 4]
Are both Linked Blocking Deque equal: false
Program 2:
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
ConcurrentLinkedDeque<String> CLD1
= new ConcurrentLinkedDeque<String>();
CLD1.add( "1" );
CLD1.add( "2" );
CLD1.add( "3" );
CLD1.add( "4" );
System.out.println( "Linked Blocking Deque 1: " + CLD1);
System.out.println( "Is CLD1 equal to CLD1: "
+ CLD1.equals(CLD1));
}
}
|
Output:
Linked Blocking Deque 1: [1, 2, 3, 4]
Is CLD1 equal to CLD1: true
Last Updated :
27 Dec, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...