java.util.ConcurrentLinkedDeque類的equals()方法用於比較指定對象與此ConcurrentLinkedDeque是否相等。當且僅當指定對象也是ConcurrentLinkedDeque,並且兩個ConcurrentLinkedDeques具有相同的大小,並且兩個ConcurrentLinkedDeques中所有對應的元素對相等時,才返回true。 (如果(e1 == null?e2 == null:e1.equals(e2)),則兩個元素e1和e2相等。)換句話說,如果兩個ConcurrentLinkedDeques包含相同順序的相同元素,則定義為相等。 。
用法:
public boolean equals(Object o)
參數:此方法將對象o作為與此ConcurrentLinkedDeque進行相等性比較的參數。
返回值:如果指定對象等於此ConcurrentLinkedDeque,則此方法返回true。
以下示例程序旨在說明ConcurrentLinkedDeque.equals()方法:
示例1:
// Java Program Demonstrate equals()
// method of ConcurrentLinkedDeque
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
// create object of ConcurrentLinkedDeque
ConcurrentLinkedDeque<Integer> CLD1
= new ConcurrentLinkedDeque<Integer>();
// Add numbers to end of ConcurrentLinkedDeque
CLD1.add(7855642);
CLD1.add(35658786);
CLD1.add(5278367);
CLD1.add(74381793);
System.out.println("Linked Blocking Deque 1: " + CLD1);
// create another object of ConcurrentLinkedDeque
ConcurrentLinkedDeque<String> CLD2
= new ConcurrentLinkedDeque<String>();
// Add numbers to end of ConcurrentLinkedDeque
CLD2.add("1");
CLD2.add("2");
CLD2.add("3");
CLD2.add("4");
System.out.println("Linked Blocking Deque 2: " + CLD2);
// using equals() function
System.out.println("Are both Linked Blocking Deque equal: "
+ CLD1.equals(CLD2));
}
}
輸出:
Linked Blocking Deque 1: [7855642, 35658786, 5278367, 74381793] Linked Blocking Deque 2: [1, 2, 3, 4] Are both Linked Blocking Deque equal: false
示例2:
// Java Program Demonstrate equals()
// method of ConcurrentLinkedDeque
// when the list contains characters
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.*;
public class GFG {
public static void main(String[] args)
throws IllegalStateException
{
// create object of ConcurrentLinkedDeque
ConcurrentLinkedDeque<String> CLD1
= new ConcurrentLinkedDeque<String>();
// Add numbers to end of ConcurrentLinkedDeque
CLD1.add("1");
CLD1.add("2");
CLD1.add("3");
CLD1.add("4");
System.out.println("Linked Blocking Deque 1: " + CLD1);
// using equals() function
System.out.println("Is CLD1 equal to CLD1: "
+ CLD1.equals(CLD1));
}
}
輸出:
Linked Blocking Deque 1: [1, 2, 3, 4] Is CLD1 equal to CLD1: true
相關用法
- Java ConcurrentLinkedDeque add()用法及代碼示例
- Java ConcurrentLinkedDeque removeFirstOccurrence()用法及代碼示例
- Java ConcurrentLinkedDeque removeLastOccurrence()用法及代碼示例
- Java ConcurrentLinkedDeque peek()用法及代碼示例
- Java ConcurrentLinkedDeque poll()用法及代碼示例
- Java ConcurrentLinkedDeque iterator()用法及代碼示例
- Java ConcurrentLinkedDeque addLast()用法及代碼示例
- Java ConcurrentLinkedDeque toArray()用法及代碼示例
- Java ConcurrentLinkedDeque addFirst()用法及代碼示例
- Java ConcurrentLinkedDeque descendingIterator()用法及代碼示例
- Java ConcurrentLinkedDeque peekFirst()用法及代碼示例
- Java ConcurrentLinkedDeque clear()用法及代碼示例
- Java ConcurrentLinkedDeque contains()用法及代碼示例
- Java ConcurrentLinkedDeque removeLast()用法及代碼示例
- Java ConcurrentLinkedDeque hashCode()用法及代碼示例
注:本文由純淨天空篩選整理自Code_r大神的英文原創作品 ConcurrentLinkedDeque equals() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。