java.util.IdentityHashMap.clear() Method
Advertisements
Description
The clear() method is used to remove all mappings from this map.
Declaration
Following is the declaration for java.util.IdentityHashMap.clear() method.
public void clear()
Parameters
NA
Return Value
NA
Exception
NA
Example
The following example shows the usage of java.util.IdentityHashMap.clear()
package com.tutorialspoint;
import java.util.*;
public class IdentityHashMapDemo {
public static void main(String args[]) {
// create identity hash map
IdentityHashMap ihmap = new IdentityHashMap();
// populate the map
ihmap.put(1, "java");
ihmap.put(2, "util");
ihmap.put(3, "package");
System.out.println("Initial Map content: " + ihmap);
// clear the map
ihmap.clear();
System.out.println("Map content after clear: " + ihmap);
}
}
Let us compile and run the above program, this will produce the following result.
Initial Map content: {1=java, 3=package, 2=util}
Map content after clear: {}