hashCode(): This method is available in java.util.HashSet 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.HashSet;public class HashSethashCode {public static void main(String[] args) {HashSet<String> hashSet = new HashSet<String>();hashSet.add("Hello");hashSet.add("Java");hashSet.add("C++");hashSet.add("Hello");System.out.println(hashSet.hashCode());}}
Output:
71976919
No comments:
Post a Comment