Java Integer hashCode() Method25 Mar 2025 | 3 min read The 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 1Output: 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 3Output: 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 4Output: Hash code Value for object is: 155 Example 5Output: Enter the desired input value: 4569 Hash code Value for object is: 4569 Next TopicJava-integer-highestonebit-method |
Java Integer reverseBytes Method The reverseBytes() method of Java Integer class numerically returns the value obtained by reversing the order of the bytes in the 2's complement binary representation of the specified integer value. Syntax: Following is the declaration of reverseBytes() method: public static int reverseBytes(int i) Parameter: DataType Parameter Description Required/Optional int i Integer value whose...
2 min read
Java Method The min() is a method of Integer class under java.lang package. This method numerically returns the minimum value amongst the two method argument specified by a user. This method can be overloaded and it takes the arguments in int, double, float and long. Note:...
2 min read
Java Method The compareUnsigned() is a method of Java Integer class which compares two integer objects numerically treating the values as unsigned. It returns the result of the value 0 if both arguments are equal; a value less than 0, if the first argument is...
3 min read
Java Method The rotateRight() method of Java Integer class returns the value obtained by rotating the two's complement binary representation of the specified int value right by the specified number of bits. (Bits shifted out of the right hand, or low-order). Bit shifting is a bitwise...
3 min read
Java method The compareTo() method is a method of Integer class under java.lang package. This method compares two integer objects numerically. It returns the result of the value 0 if Integer is equal to the argument Integer, a value less than 0 if Integer is...
2 min read
Java Method The highestOneBit() method is a method of Integer class under java.lang package. This method returns int value with at most a single one-bit, in the position of the highest-order ("leftmost") one-bit in the specified int value. If the specified value has no one-bits...
2 min read
Java method The decode() method is a static method of Integer class under java.lang package. The main function of this method is to decode a string which is written in the form of (" ") into an integer value. The decode() method also accepts decimal, hexadecimal,...
2 min read
Java Method The toOctalString() method of Integer class returns a string representation of the integer argument as an unsigned integer in octal base 8. The following characters are used as octal digits: 0 1 2 3 4 5 6 7 Note: If the argument is negative, the unsigned...
2 min read
The Java Integer class comes under the Java.lang.Number package. This class wraps a value of the primitive type int in an object. An object of Integer class contains a single field of type int value. Java Integer Methods The Java Integer class provides several methods for converting...
3 min read
Java Method The lowestOneBit() method is a method of Integer class under java.lang package. This method returns int value with at most a single one-bit, in the position of the lowest-order ("rightmost") one-bit in the specified int value. If the specified value has no one-bits...
2 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India