clear(): This method is available in java.util.IdentityHashMap class of Java.
Syntax:
void java.util.IdentityHashMap.clear()
This method removes all of the mappings from this map.
Note: The map will be empty after this call returns.
Parameters: NA
Returns: NA
Exceptions: NA
Approach
Java
import java.util.IdentityHashMap;public class IdentityHashMapclear {public static void main(String args[]) {IdentityHashMap<String, Integer> identityHashMap =new IdentityHashMap<String, Integer>();identityHashMap.put("Java", 1);identityHashMap.put("Hello", 2);System.out.println("Map before clear: " +identityHashMap);identityHashMap.clear();System.out.println("Map after clear: " +identityHashMap);}}
Output:
Map before clear: {Java=1, Hello=2}
Map after clear: {}
No comments:
Post a Comment