- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove all elements in Java IdentityHashMap
Use the clear() method to remove all the elements from IdentityHashMap in Java.
Create a IdentityHashMap and add some elements
Map<String, Integer> m = newIdentityHashMap<String, Integer>(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250); m.put("9", 350); m.put("10", 450);
Now, let us remove all the element
m.clear();
The following is an example to remove all elements in IdentityHashMap in Java
Example
import java.util.*; public class Demo { public static void main(String[] args) { Map<String, Integer> m = newIdentityHashMap<String, Integer>(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250); m.put("9", 350); m.put("10", 450); System.out.println("IdentityHashMap elements
"+ m); System.out.println("Size = " + m.size()); // remove all elements m.clear(); System.out.println("
Updated IdentityHashMap elements = "+ m); System.out.println("Size = " + m.size()); } }
Output
The output is as follows
IdentityHashMap elements {2=200, 4=150, 9=350, 7=90, 10=450, 6=50, 5=110, 8=250, 1=100, 3=300} Size = 10 Updated IdentityHashMap elements = {} Size = 0
- Related Articles
- Remove an element from IdentityHashMap in Java
- Remove all elements from TreeSet in Java
- Remove all elements from Java NavigableMap
- Remove all elements from Java LinkedHashSet
- Remove all elements from a HashSet in Java
- Remove all elements from the ArrayList in Java
- How to remove all elements of ArrayList in Java?
- Java Program to remove all elements from a set in Java
- Create IdentityHashMap in Java
- Clone IdentityHashMap in Java
- IdentityHashMap class in Java
- IdentityHashMap size() method in Java
- Remove all elements from OrderedDictionary in C#
- Java IdentityHashMap containsValue() method
- Java IdentityHashMap clear() method

Advertisements