LinkedBlockingDeque equals() method in Java with Example
The equals() method of java.util.LinkedBlockingDeque class is used to compare the specified object with this LinkedBlockingDeque for equality. Returns true if and only if the specified object is also a LinkedBlockingDeque, both LinkedBlockingDeques have the same size, and all corresponding pairs of elements in the two LinkedBlockingDeques are equal. (Two elements e1 and e2 are equal if (e1==null ? e2==null : e1.equals(e2)).) In other words, two LinkedBlockingDeques 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 LinkedBlockingDeque.
Returns Value: This method returns true if the specified object is equal to this LinkedBlockingDeque.
Below examples illustrates the LinkedBlockingDeque.equals() method:
Program 1:
// Java Program Demonstrate equals() // method of LinkedBlockingDeque import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of LinkedBlockingDeque LinkedBlockingDeque<Integer> LBD1 = new LinkedBlockingDeque<Integer>(); // Add numbers to end of LinkedBlockingDeque LBD1.add(7855642); LBD1.add(35658786); LBD1.add(5278367); LBD1.add(74381793); System.out.println("Linked Blocking Deque 1: " + LBD1); // create another object of LinkedBlockingDeque LinkedBlockingDeque<String> LBD2 = new LinkedBlockingDeque<String>(); // Add numbers to end of LinkedBlockingDeque LBD2.add("1"); LBD2.add("2"); LBD2.add("3"); LBD2.add("4"); System.out.println("Linked Blocking Deque 2: " + LBD2); // using equals() function System.out.println("Are both Linked Blocking Deque equal: " + LBD1.equals(LBD2)); } } |
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:
// Java Program Demonstrate equals() // method of LinkedBlockingDeque // when the list contains characters import java.util.concurrent.LinkedBlockingDeque; import java.util.*; public class GFG { public static void main(String[] args) throws IllegalStateException { // create object of LinkedBlockingDeque LinkedBlockingDeque<String> LBD1 = new LinkedBlockingDeque<String>(); // Add numbers to end of LinkedBlockingDeque LBD1.add("1"); LBD1.add("2"); LBD1.add("3"); LBD1.add("4"); System.out.println("Linked Blocking Deque 1: " + LBD1); // using equals() function System.out.println("Is LBD1 equal to LBD1: " + LBD1.equals(LBD1)); } } |
Linked Blocking Deque 1: [1, 2, 3, 4] Is LBD1 equal to LBD1: true
Recommended Posts:
- LinkedBlockingDeque add() method in Java
- LinkedBlockingDeque put() method in Java
- LinkedBlockingDeque take() method in Java
- LinkedBlockingDeque pop() method in Java
- LinkedBlockingDeque contains() method in Java
- LinkedBlockingDeque clear() method in Java
- LinkedBlockingDeque getFirst() method in Java
- LinkedBlockingDeque descendingIterator() method in Java
- LinkedBlockingDeque pollFirst() method in Java
- LinkedBlockingDeque peekFirst() method in Java
- LinkedBlockingDeque size() method in Java
- LinkedBlockingDeque removeFirstOccurrence() method in Java
- LinkedBlockingDeque removeLastOccurrence() method in Java
- LinkedBlockingDeque takeLast() method in Java
- LinkedBlockingDeque toArray() method in Java with Example
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.



