Home » Java programming language

Java Object Class int hashCode() method with Example

Java Object class int hashCode() method: Here, we are going to learn about the int hashCode() method of Object class with its syntax and example.
Submitted by Preeti Jain, on June 25, 2019

Object Class int hashCode()

  • This method is available in package java.lang.Object.hashCode().
  • This method is used to return hashcode for the object.


    int hashCode(){


We don't pass any object as a parameter in the method of the Object.

Return value:

The return type of this method is int that means this method returns hashcode of the object and return type is int that means hashcode is in number format.

Java program to demonstrate example of Object Class hashCode() method

import java.lang.Object;

public class ObjectClass {
    public static void main(String[] args) {

        // Create a new object for Integer type
        Integer in = new Integer(10);

        // Display hashcode of Integer class object
        System.out.println("The hashCode of Integer class object in is :" + in .hashCode());

        // Create a new object for String type
        String str = new String("Hello, Welcome in java world");

        // Display hashcode of String class object
        System.out.println("The hashCode of String class object str is :" + str.hashCode());



D:\Programs>java ObjectClass
The hashCode of Integer class object in is :10
The hashCode of String class object str is :508604331


Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.