Java ConcurrentLinkedDeque hashCode()方法与实例
Java中 ConcurrentLinkedDeque 的 hashCode() 方法用于获取ConcurrentLinkedDeque这个实例的hashCode值。它返回一个整数值,即ConcurrentLinkedDeque这个实例的hashCode值。
语法
public int hashCode()
参数: 该函数没有参数。
返回值: 该方法返回一个整数值,即ConcurrentLinkedDeque这个实例的hashCode值。
下面的程序说明了ConcurrentLinkedDeque.hashCode()方法。
程序1 :
// 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<Integer> CLD
= new ConcurrentLinkedDeque<Integer>();
// 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
代码2 。
// 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<String> CLD
= new ConcurrentLinkedDeque<String>();
// 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
极客教程