Online Java Compiler By
JavaTpoint.com
import java.util.IdentityHashMap; class Student{ private int roll; private String name; private int standard; public Student(int roll,String name,int standard){ this.roll = roll; this.name = name; this.standard = standard; } public String disp(){ return roll+" "+name+" "+standard; } } public class IdentityHashMapHashCodeExample2 { public static void main(String[] args) { //Creating Objects of Student class Student stud1 = new Student(1 ,"Ram ",10); Student stud2 = new Student(2 ,"Shyam ",10); Student stud3 = new Student(3 ,"Aman ",12); Student stud4 = new Student(4 ,"Harsh ",12); Student stud5 = new Student(5 ,"Shivam",11); //Creating an instance of IdentityHashMap IdentityHashMap
map = new IdentityHashMap
(5); //Inserting the Student class objects into IdentityHashMap map.put(1,stud1); map.put(2,stud2); map.put(3,stud3); map.put(4,stud4); //Getting hashCode value for this IdentityHashMap System.out.println(map.hashCode()); } }
Output