Java中的 ConcurrentLinkedDeque hashCode() 方法及示例
Java中ConcurrentLinkedDeque的hashCode()方法用于获取该 ConcurrentLinkedDeque 实例的 hashCode 值。它返回一个整数值,这是 ConcurrentLinkedDeque 实例的 hashCode 值。
句法:
public int hashCode()
参数:此函数没有参数。
返回值:该方法返回一个整数值,该整数值是该 ConcurrentLinkedDeque 实例的 hashCode 值。
下面的程序说明了 ConcurrentLinkedDeque.hashCode() 方法:
方案一:
// Java Program Demonstrate hashCode()
// 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 CLD
= new ConcurrentLinkedDeque();
// Add numbers to end of ConcurrentLinkedDeque
CLD.add(7855642);
CLD.add(35658786);
CLD.add(5278367);
CLD.add(74381793);
System.out.println("Linked Blocking Deque: " + CLD);
// Get the hashCode value
// using hashCode() value
System.out.println("HashCode value: "
+ CLD.hashCode());
}
}
输出:
Linked Blocking Deque: [7855642, 35658786, 5278367, 74381793]
HashCode value: 2101973421
方案二:
// Java Program Demonstrate hashCode()
// 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 CLD
= new ConcurrentLinkedDeque();
// Add numbers to end of ConcurrentLinkedDeque
CLD.add("1");
CLD.add("2");
CLD.add("3");
CLD.add("4");
System.out.println("Linked Blocking Deque: " + CLD);
// Get the hashCode value
// using hashCode() value
System.out.println("HashCode value: "
+ CLD.hashCode());
}
}
输出:
Linked Blocking Deque: [1, 2, 3, 4]
HashCode value: 2101973421