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


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


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


相关用法


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