Integer hashCode() Method in Java Last Updated : 05 Dec, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The java.lang.Integer.hashCode() method of Integer class in Java is used to return the hash code for a particular Integer . Syntax: public int hashCode() Parameters : The method does not take any parameters. Return Value: The method returns a hash code integer value for this object, which is equal to the uncomplicated primitive integer value, represented by this Integer object. Below programs illustrate the use of hashCode() of Integer class: Program 1: When integer data type is passed. java // Java program to demonstrate working // of Java.lang.Integer.hashCode() Method import java.lang.*; public class Geeks { public static void main(String[] args) { // Object s_int created Integer s_int = new Integer("223"); // Returning a hash code value for this object int hashcodevalue = s_int.hashCode(); System.out.println("Hash code Value for object = " + hashcodevalue); } } Output: Hash code Value for object = 223 Program 2: When String data type is passed. Note: This causes RuntimeErrors like NumberFormatException java // Java program to demonstrate working // of Java.lang.Integer.hashCode() Method import java.lang.*; public class Geeks { public static void main(String[] args) { // object s_int created Integer s_int = new Integer("gfg"); // Returning a hash code value for this object. int hashcodevalue = s_int.hashCode(); System.out.println("Hash code Value for object = " + hashcodevalue); } } Output: Exception in thread "main" java.lang.NumberFormatException: For input string: "gfg" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer.(Integer.java:867) at Geeks.main(Geeks.java:9) Comment More infoAdvertise with us Next Article Java Integer compare() method A ankita_chowrasia Follow Improve Article Tags : Misc Java Java-lang package Java-Functions Java-Integer +1 More Practice Tags : JavaMisc Similar Reads Integer decode() Method in Java It is often seen that any integer within (" ") is also considered as string, then it is needed to decode that into the integer. The main function of java.lang.Integer.decode() method is to decode a String into an Integer. The method also accepts decimal, hexadecimal, and octal numbers. Syntax : publ 2 min read Set hashCode() Method in Java In Java, the hashCode() method is defined in the Object class and is used to generate a hash code for objects. It plays a very important role in hash-based collections like HashMap, HashSet, and HashTable. Example 1: This example demonstrates how hashCode() is used to get the hash code of the HashSe 2 min read Java Integer compare() method The compare() method of Integer class of java.lang package compares two integer values (x, y) given as a parameter and returns the value zero if (x==y), if (x < y) then it returns a value less than zero and if (x > y) then it returns a value greater than zero. Syntax : public static int compar 2 min read Java Integer bitCount() Method The bitCount() method of Integer class of java.lang package returns the count of set bits in a positive number. For negative numbers, it returns the count of set bits in its 2s complement form. This function is sometimes referred to as the population count. Syntax:public static int bitCount(int n)Pa 2 min read Vector hashCode() Method in Java The java.util.vector.hashCode() method in Java is used to get the hashcode value of this vector. Syntax: Vector.hashCode() Parameters: The method does not take any parameter. Return Value: The method returns hash code value of this Vector which is of Integer type. Below programs illustrate the Java. 2 min read IdentityHashMap hashCode() Method in Java The java.util.IdentityHashMap.hashCode() method in Java is used to fetch the hash code value of a particular this IdentityHashMap. 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 hashc 2 min read Like