This Java Example shows how to remove all the Entries from the specified Linked HashMap object in java.
Remove All Entries of Java LinkedHashMap Example
This Java Example shows how to remove all the Entries from the specified
Linked HashMap object in java. To remove all of the Entries from Linked HashMap object
we use void clear() method. This method removes all of the
mappings from this map.
Example: ClearEntriesofLinked HashMap.java
package devmanuals.com;
import java.util.*;
public class ClearEntriesofLinkedHashMap {
public static void main(String args[]) {
LinkedHashMap Lhm = new LinkedHashMap();
Lhm.put(1, "Gyan");
Lhm.put(6, "Ankit");
Lhm.put(5, "Arun");
Lhm.put(4, "Anand");
Lhm.put(3, "Ram");
System.out.println("The Size of LinkedHashMap are : " + Lhm.size());
Lhm.clear();
System.out.println("The size of map after removal : " + Lhm.size());
System.out.println("The LinkedHashMap entries is as follows : " + Lhm);
}
}
Output:
| The Size of LinkedHashMap are : 5
The size of map after removal : 0 The LinkedHashMap entries is as follows : {} |

[ 0 ] Comments