Java Integer hashCode() MethodThe hashCode() method is a Java Integer class method which returns the hash code for the given inputs. There are two different types of Java hashCode() method which can be differentiated depending on its parameter. These are:
hashCode() MethodThe hashCode() is a method of Java Integer Class which determines the hash code for a given Integer. It overrides hashCode in class Object. By default, this method returns a random integer that is unique for each instance. hashCode(int value) MethodThe hashCode(int value) is an inbuilt Java Integer Class method which determines a hash code for a given int value. This method is compatible with Integer.hashCode(). Syntax:Following is the declaration of hashCode() method: Parameter:
Returns:
Exceptions:InputMismatchException, NumberFormatException Compatibility Version:
Example 1Test it NowOutput: Hash code Value for object is: 155 Example 2Output: 1. Enter the desired input value: 4343 Hash code Value for object is: 4343 2. Enter the desired input value: abcd Exception in thread "main" java.util.InputMismatchException at java.util.Scanner.throwFor(Scanner.java:864) at java.util.Scanner.next(Scanner.java:1485) at java.util.Scanner.nextInt(Scanner.java:2117) at java.util.Scanner.nextInt(Scanner.java:2076) at myPackage.IntegerHashCodeExample1.main(IntegerHashCodeExample1.java:11) Example 3Test it NowOutput: Exception in thread "main" java.lang.NumberFormatException: For input string: "abcd" at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.lang.Integer.parseInt(Integer.java:580) at java.lang.Integer. Example 4Test it NowOutput: Hash code Value for object is: 155 Example 5Output: Enter the desired input value: 4569 Hash code Value for object is: 4569
Next TopichighestOneBit() Method
|