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 IdentityHashMapCloneExample2 { 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); //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); //Creating an Object Object obj = map.clone(); System.out.println(obj); } }
Output