- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Get Hash Code for Integer in Java
The HashCode for an Integer can be obtained using the hashCode() method in Java. This method does not accept any parameters and it returns a hash code value of the Integer object.
A program that demonstrates the hashCode() method in Java is given as follows:
Example
import java.lang.*; public class Demo { public static void main(String args[]) { Integer i = new Integer(60); System.out.println("The integer value is: " + i); System.out.println("The Hashcode for the above value is: " + i.hashCode()); } }
Output
The integer value is: 60 The Hashcode for the above value is: 60
Now let us understand the above program.
The Integer i is defined. Then the Integer value is printed and its HashCode is also printed using the hashCode() method. A code snippet which demonstrates this is as follows:
Integer i = new Integer(60); System.out.println("The integer value is: " + i); System.out.println("The Hashcode for the above value is: " + i.hashCode());
Advertisements
To Continue Learning Please Login
Login with Google