OptionalInt hashCode() method in Java with examples Last Updated : 01 May, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The hashCode() method help us to get the hash code of the value, if Int value is present, otherwise 0 (zero) if no Int value is present in OptionalInt object. Syntax: public int hashCode() Parameters: This method accepts does not accepts any parameter. Return value: This method returns hash code value of the present value or 0 if no value is present. Below programs illustrate hashCode() method: Program 1: Java // Java program to demonstrate // OptionalInt.hashCode() method import java.util.OptionalInt; public class GFG { public static void main(String[] args) { // create a OptionalInt instance OptionalInt opInt = OptionalInt.of(253); System.out.println("OptionalInt: " + opInt.toString()); // get hashCode value using hashCode() System.out.println("HashCode value: " + opInt.hashCode()); } } Output: OptionalInt: OptionalInt[253] HashCode value: 253 Program 2: Java // Java program to demonstrate // OptionalInt.hashCode() method import java.util.OptionalInt; public class GFG { public static void main(String[] args) { // create a OptionalInt instance OptionalInt opInt = OptionalInt.empty(); System.out.println("OptionalInt: " + opInt.toString()); // get hashCode value using hashCode() System.out.println("HashCode value: " + opInt.hashCode()); } } Output: OptionalInt: OptionalInt.empty HashCode value: 0 References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalInt.html#hashCode() Comment More infoAdvertise with us Next Article Period hashCode() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-OptionalInt Practice Tags : Java Similar Reads Optional hashCode() method in Java with examples The hashCode() method of java.util.Optional class in Java is used to get the hashCode value of this Optional instance. If there is no value present in this Optional instance, then this method returns 0. Syntax: public int hashCode() Parameter: This method do not accepts any parameter. Return Value: 1 min read Path hashCode() method in Java with Examples The Java Path interface was added to Java NIO in Java 7. hashCode() method of java.nio.file.Path used to return a hash code for this path after computing hashcode. The hashcode is always the same if the object doesnât change. Hashcode is a unique code generated by the JVM at time of object creation. 2 min read Period hashCode() method in Java with Examples The hashCode() method of Period class in Java is used to get the generated hashCode for this period. Syntax: public int hashCode() Parameters: This method does not accepts any parameter. Return Value: This method returns the hashCode generated for the given period. Below programs illustrate the hash 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 Sho 2 min read StringWriter hashCode() method in Java with Examples The hashCode() method of StringWriter Class in Java is used to get the HashCode value of this StringWriter instance. This method does not accepts any parameter and returns the required int value. Syntax: public int hashCode() Parameters: This method accepts does not accepts any parameter. Return Val 2 min read Properties hashCode() method in Java with Examples The hashCode() method of Properties class is used to generate a hashCode for the given Properties containing key and values. Syntax: public int hashCode() Parameters: This method has no argument. Returns: This method returns the hashCode value for the given map. Below programs show the implementatio 2 min read Like