当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Java ConcurrentLinkedDeque equals()用法及代码示例


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


相关用法


注:本文由纯净天空筛选整理自Code_r大神的英文原创作品 ConcurrentLinkedDeque equals() method in Java with Example。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。