ConcurrentLinkedDeque 中的 hashCode() 方法及示例
Java 中的 ConcurrentLinkedDeque 的 hashCode() 方法用于获取此 ConcurrentLinkedDeque 的哈希码值。它返回一个整数值,它是此 ConcurrentLinkedDeque 的哈希码值。
语法:
public int hashCode()
参数: 该函数没有参数。
返回值: 该方法返回一个整数值,它是此 ConcurrentLinkedDeque 的哈希码值。
以下程序示例说明了 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
// 当列表包含字符时
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
极客教程