java.util.LinkedBlockingDeque類的equals()方法用於比較指定對象與此LinkedBlockingDeque是否相等。當且僅當指定對象也是LinkedBlockingDeque,且兩個LinkedBlockingDeques具有相同的大小,並且兩個LinkedBlockingDeques中所有對應的元素對相等時,才返回true。 (如果(e1 == null?e2 == null:e1.equals(e2)),則兩個元素e1和e2相等。)換句話說,如果兩個LinkedBlockingDeques包含相同順序的相同元素,則它們被定義為相等。 。
用法:
public boolean equals(Object o)
參數:此方法將對象o作為要與此LinkedBlockingDeque進行相等性比較的參數。
返回值:如果指定對象等於此LinkedBlockingDeque,則此方法返回true。
以下示例說明了LinkedBlockingDeque.equals()方法:
示例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
示例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
相關用法
- Java LinkedBlockingDeque take()用法及代碼示例
- Java LinkedBlockingDeque contains()用法及代碼示例
- Java LinkedBlockingDeque pop()用法及代碼示例
- Java LinkedBlockingDeque add()用法及代碼示例
- Java LinkedBlockingDeque put()用法及代碼示例
- Java LinkedBlockingDeque toString()用法及代碼示例
- Java LinkedBlockingDeque remainingCapacity()用法及代碼示例
- Java LinkedBlockingDeque putLast()用法及代碼示例
- Java LinkedBlockingDeque offer()用法及代碼示例
- Java LinkedBlockingDeque isEmpty()用法及代碼示例
- Java LinkedBlockingDeque push()用法及代碼示例
- Java LinkedBlockingDeque element()用法及代碼示例
- Java LinkedBlockingDeque getFirst()用法及代碼示例
- Java LinkedBlockingDeque toArray()用法及代碼示例
- Java LinkedBlockingDeque clear()用法及代碼示例
注:本文由純淨天空篩選整理自Code_r大神的英文原創作品 LinkedBlockingDeque equals() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。