java.util.AbstractList 類的 hashCode() 方法用於返回此列表的哈希碼值。
用法:
public int hashCode()
返回值:此方法返回此列表的哈希碼值。
以下是說明 hashCode() 方法的示例。
範例1:
// Java program to demonstrate
// hashCode() method
// for Integer value
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
try {
// Creating object of AbstractList<Integer>
AbstractList<Integer>
arrlist1 = new ArrayList<Integer>();
// Populating arrlist1
arrlist1.add(10);
arrlist1.add(20);
arrlist1.add(30);
arrlist1.add(40);
arrlist1.add(50);
// print arrlist1
System.out.println("ArrayListlist:" + arrlist1);
// getting the value at the index 3
// using get() method
int code = arrlist1.hashCode();
// print the value
System.out.println("HashCode:" + code);
}
catch (IndexOutOfBoundsException e) {
System.out.println("Exception thrown:" + e);
}
}
}
輸出:
ArrayListlist:[10, 20, 30, 40, 50] HashCode:38490301
範例2:
// Java program to demonstrate
// hashCode() method
// for String value
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
try {
// Creating object of AbstractList<String>
AbstractList<String>
arrlist1 = new ArrayList<String>();
// Populating arrlist1
arrlist1.add("A");
arrlist1.add("B");
arrlist1.add("C");
arrlist1.add("D");
arrlist1.add("E");
// print arrlist1
System.out.println("ArrayListlist:"
+ arrlist1);
// getting the value at the index 3
// using get() method
int code = arrlist1.hashCode();
// print the value
System.out.println("HashCode:" + code);
}
catch (IndexOutOfBoundsException e) {
System.out.println("Exception thrown:" + e);
}
}
}
輸出:
ArrayListlist:[A, B, C, D, E] HashCode:90690786
相關用法
- Java AbstractList addAll()用法及代碼示例
- Java AbstractList clear()用法及代碼示例
- Java AbstractList equals()用法及代碼示例
- Java AbstractList get()用法及代碼示例
- Java AbstractList iterator()用法及代碼示例
- Java AbstractList lastIndexOf()用法及代碼示例
- Java AbstractList indexOf()用法及代碼示例
- Java AbstractList listIterator()用法及代碼示例
- Java AbstractList remove()用法及代碼示例
- Java AbstractList set()用法及代碼示例
- Java AbstractList add(E ele)用法及代碼示例
- Java AbstractList subList()用法及代碼示例
- Java AbstractList add(int index, E element)用法及代碼示例
- Java AbstractList用法及代碼示例
- Java 8 Clock hashCode()用法及代碼示例
- Java Boolean hashCode()用法及代碼示例
- Java Byte hashCode()用法及代碼示例
- Java Short hashCode()用法及代碼示例
- Java Double hashCode()用法及代碼示例
- Java AbstractMap hashCode()用法及代碼示例
- Java AbstractSet hashCode()用法及代碼示例
- Java Float hashCode()用法及代碼示例
- Java Duration hashCode()用法及代碼示例
- Java Instant hashCode()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 AbstractList hashCode() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。