📌  相关文章
📜  Java中的 AbstractSequentialList hashCode() 方法及示例

📅  最后修改于: 2022-05-13 01:55:38.950000             🧑  作者: Mango

Java中的 AbstractSequentialList hashCode() 方法及示例

Java中AbstractSequentialListhashCode()方法用于获取此 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 arr
            = new LinkedList();
  
        // 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 arr
            = new LinkedList();
  
        // 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