Open In App

List hashCode() Method in Java with Examples

Last Updated : 02 Jan, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

This method is used to generate the hashCode for the given list.

Syntax:

int hashCode()

Parameters: This function has no parameter.

Returns: This function returns the hashCode value for the given list.

Below programs show the implementation of this method.

Program 1:




// Java code to show the implementation of
// hashCode method in list interface
import java.util.*;
public class GfG {
  
    // Driver code
    public static void main(String[] args)
    {
  
        // Initializing a list of type Linkedlist
        List<Integer> l = new LinkedList<>();
        l.add(10);
        l.add(15);
        l.add(20);
        System.out.println(l);
  
        int hash = l.hashCode();
  
        System.out.println(hash);
    }
}


Output:

[10, 15, 20]
39886

Program 2: Below is the code to show implementation of list.hashCode() using Linkedlist.




// Java code to show the implementation of
// hashCode method in list interface
import java.util.*;
public class GfG {
  
    // Driver code
    public static void main(String[] args)
    {
  
        // Initializing a list of type Linkedlist
        List<String> l = new LinkedList<>();
        l.add("10");
        l.add("15");
        l.add("20");
        System.out.println(l);
  
        int hash = l.hashCode();
  
        System.out.println(hash);
    }
}


Output:

[10, 15, 20]
1586008

Reference:
Oracle Docs



Previous Article
Next Article

Similar Reads

Java 8 Clock hashCode() method with Examples
Java Clock class is part of Date Time API, java.time.Clock, of Java. The Java Date Time API was added from Java version 8. hashCode() method of Clock class returns the hash code for this Clock Object. Clocks object overrides this method based on their state. If clock object is not overridden, the behavior of this method is defined by Object.hashCod
2 min read
Boolean hashCode() method in Java with examples
The hashCode() method of Boolean class is a built in method to return a int hashcode value corresponding to the Boolean object. Syntax BooleanObject.hashCode() Return Type: It returns a int hashcode value corresponding to the Boolean object. It returns 1231 if the Boolean object stores the value true. It returns 1237 if the Boolean object stores th
1 min read
Byte hashCode() method in Java with examples
The hashCode() method of Byte class is a built in method in Java which is used to return the hash code of the ByteObject. Note: The hashCode() returns the same value as intValue(). Syntax ByteObject.hashCode() Return Value: It return an int value which represents the hashcode of the specified Byte object. Below is the implementation of hashCode() m
2 min read
Short hashCode() method in Java with Examples
The hashCode() method of Short class is a built in method in Java which is used to return the hash code of the ShortObject. Note: The hashCode() returns the same value as intValue(). Syntax ShortObject.hashCode() Return Value: It return an int value which represents the hashcode of the specified Short object. Below is the implementation of hashCode
2 min read
Double hashCode() method in Java with examples
The hashCode() method of Double class is a built-in method use to return the hashcode value of this Double object. Syntax: DoubleObject.hashCode() Parameters: It takes no parameters. Return Type: It returns an int value. The value returned is (int)(v^(v&gt;&gt;&gt;32)) where v is a long variable equal to Double.doubleToLongBits(this.doubleValue()).
1 min read
AbstractList hashCode() method in Java with Examples
The hashCode() method of java.util.AbstractList class is used to return the hash code value for this list. Syntax: public int hashCode() Returns Value: This method returns the hash code value for this list. Below are the examples to illustrate the hashCode() method. Example 1: // Java program to demonstrate // hashCode() method // for Integer value
2 min read
AbstractMap hashCode() Method in Java with Examples
The AbstractMap.hashCode() method in Java is used to fetch the hash code value of a particular this AbstractMap. A map consists of a number of buckets to store the key-value pair. Each bucket has a unique identity and when a key-value pair is inserted into a bucket, the key's hashcode is matched with the identifier of the bucket, and if its a match
2 min read
AbstractSet hashCode() Method in Java with Examples
The AbstractSet.hashCode() method in Java AbstractSet is used to fetch the hash code value of a particular this AbstractSet. A set consists of a number of buckets to store the elements. Each bucket has a unique identity and when an element is inserted into a bucket, its hashcode is matched with the identifier of the bucket, and if its a match the e
2 min read
Float hashCode() method in Java with examples
The hashCode() method method in Float Class is a built-in method in Java that return the hashcode value of this Float object. Syntax: public int hashCode() Parameters: It takes no parameters. Returns: The function returns a hash code value for this object. Below is the implementation of hashCode() method: Example 1: // Java code to demonstrate // F
1 min read
Duration hashCode() method in Java with Examples
The hashCode() method of Duration Class in java.time package is used to get the hashCode value of this duration. Syntax: public int hashCode() Parameters: This method do not accepts any parameter. Return Value: This method returns an int value which is the hashCode value of this duration. Below examples illustrate the Duration.hashCode() method: Ex
1 min read