Online Java Compiler By
JavaTpoint.com
import java.util.IdentityHashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class IdentityHashMapClearExample1 { public static void main(String[] args) { //Creating an object of IdentityHashMap class IdentityHashMap
map = new IdentityHashMap
(5); //Putting key-value pairs inside map map.put("Java", 1); map.put("is", 2); map.put("the", 3); map.put("best", 4); map.put("programming", 5); map.put("language", 6); //Get a set of all entries Set set = map.entrySet(); //Declare an iterator Iterator itr = set.iterator(); //Displaying all the entries while(itr.hasNext()) { Map.Entry m = (Map.Entry)itr.next(); System.out.print(m.getKey()+"->"); System.out.println(m.getValue()); } //Clearing the Map map.clear(); //Checking if the Map is empty System.out.println(map.isEmpty()); } }
Output