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 IdentityHashMapValuesExample2 { 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
map1 = new IdentityHashMap
(5); //Inserting the Student class objects into IdentityHashMap map1.put(1,stud1); map1.put(2,stud2); map1.put(3,stud3); map1.put(4,stud4); //Displaying the size of the map1 System.out.println(map1.size()); //Displaying elements of map1 System.out.println(map1); //Displaying a collection of all the values System.out.println(map1.values()); } }
Output