📜  Java中的 LinkedBlockingDeque hashCode() 方法与示例

📅  最后修改于: 2022-05-13 01:55:20.300000             🧑  作者: Mango

Java中的 LinkedBlockingDeque hashCode() 方法与示例

Java中LinkedBlockingDequehashCode()方法用于获取该 LinkedBlockingDeque 实例的 hashCode 值。它返回一个整数值,该值是 LinkedBlockingDeque 实例的 hashCode 值。

句法:

public int hashCode()

参数:此函数没有参数。

返回:该方法返回一个整数值,它是 LinkedBlockingDeque 实例的 hashCode 值。

下面的示例说明了 LinkedBlockingDeque.hashCode() 方法:

方案一:

// Java Program Demonstrate hashCode()
// 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 LBD
            = new LinkedBlockingDeque();
  
        // Add numbers to end of LinkedBlockingDeque
        LBD.add(7855642);
        LBD.add(35658786);
        LBD.add(5278367);
        LBD.add(74381793);
  
        System.out.println("Linked Blocking Deque: " + LBD);
  
        // Get the hashCode value
        // using hashCode() value
        System.out.println("HashCode value: "
                           + LBD.hashCode());
    }
}
输出:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
HashCode value: 2101973421

方案二:

// Java Program Demonstrate hashCode()
// 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 LBD
            = new LinkedBlockingDeque();
  
        // Add numbers to end of LinkedBlockingDeque
        LBD.add("1");
        LBD.add("2");
        LBD.add("3");
        LBD.add("4");
  
        System.out.println("Linked Blocking Deque: " + LBD);
  
        // Get the hashCode value
        // using hashCode() value
        System.out.println("HashCode value: "
                           + LBD.hashCode());
    }
}
输出:
Linked Blocking Deque: [1, 2, 3, 4]
HashCode value: 2101973421