LinkedHashSet hashCode() in Java

hashCode(): This method is available in java.util.LinkedHashSet class of Java.

Syntax:

int java.util.AbstractSet.hashCode()

This method returns the hash code value for this set. The hash code of a set is defined to be the sum of the hash codes of the elements in the set, where the hash code of a null element is defined to be zero.

Parameters: NA

Returns: the hash code value for this set.

Exceptions: NA

Approach

Java

import java.util.LinkedHashSet;

public class LinkedHashSethashCode {
    public static void main(String[] args) {

        LinkedHashSet<String> linkedHashSet =
new LinkedHashSet<>();

        linkedHashSet.add("Hello");
        linkedHashSet.add("Java");

        System.out.println(linkedHashSet.hashCode());

    }
}

Output:

71911156


No comments:

Post a Comment