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 IdentityHashMapContainsValueExample2 { 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 System.out.println(map.put(1,stud1)); System.out.println(map.put(2,stud2)); System.out.println(map.put(3,stud3)); System.out.println(map.put(4,stud4)); //Using containsValue() method System.out.println(map.containsValue(stud1)); System.out.println(map.containsValue("Random")); System.out.println(map.containsValue(stud4)); System.out.println(map.containsValue(stud5)); } }
Output