當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Java AbstractSequentialList hashCode()用法及代碼示例


Java中的AbstractSequentialList的hashCode()方法用於獲取AbstractSequentialList的實例的hashCode值。它返回一個整數值,該值是此AbstractSequentialList實例的hashCode值。

用法:

public int hashCode()

參數:此函數沒有參數。


返回:該方法返回一個整數值,該值是此AbstractSequentialList實例的hashCode值。

以下示例說明了AbstractSequentialList.hashCode()方法:

範例1:

// Java code to demonstrate the working of 
// hashCode() method in AbstractSequentialList 
  
import java.util.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
        // creating an AbstractSequentialList 
        AbstractSequentialList<Integer> arr 
            = new LinkedList<Integer>(); 
  
        // using add() to initialize values 
        // [1, 2, 3, 4] 
        arr.add(1); 
        arr.add(2); 
        arr.add(3); 
        arr.add(4); 
  
        // print AbstractSequentialList 
        System.out.println("AbstractSequentialList:"
                           + arr); 
  
        // Get the hashCode value 
        // using hashCode() value 
        System.out.println("HashCode value:"
                           + arr.hashCode()); 
    } 
}
輸出:
AbstractSequentialList:[1, 2, 3, 4]
HashCode value:955331

範例2:

// Java code to demonstrate the working of 
// hashCode() method in AbstractSequentialList 
  
import java.util.*; 
  
public class GFG { 
    public static void main(String[] args) 
    { 
        // creating an AbstractSequentialList 
        AbstractSequentialList<String> arr 
            = new LinkedList<String>(); 
  
        // using add() to initialize values 
        // [Geeks, For, ForGeeks, GeeksForGeeks] 
        arr.add("Geeks"); 
        arr.add("For"); 
        arr.add("ForGeeks"); 
        arr.add("GeeksForGeeks"); 
  
        // print AbstractSequentialList 
        System.out.println("AbstractSequentialList:"
                           + arr); 
  
        // Get the hashCode value 
        // using hashCode() value 
        System.out.println("HashCode value:"
                           + arr.hashCode()); 
    } 
}
輸出:
AbstractSequentialList:[Geeks, For, ForGeeks, GeeksForGeeks]
HashCode value:-927254198


相關用法


注:本文由純淨天空篩選整理自Code_r大神的英文原創作品 AbstractSequentialList hashCode() method in Java with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。