This Java Example shows how to remove all the Entries from the specified TreeMap object in java.
Remove All Entries of Java TreeMap Example
This Java Example shows how to remove all the Entries from the specified TreeMap object
in java. To remove all of the Entries from TreeMap object
we use void clear() method. This method removes all of the
mappings from this map.
Example: RemoveAllEntriesofTreeMap.java
package devmanuals.com;
import java.util.*;
public class RemoveAllEntriesofTreeMap {
public static void main(String args[]) {
TreeMap Tmap = new TreeMap();
Tmap.put(1, "Singh");
Tmap.put(3, "Kumar");
Tmap.put(4, "Kumar");
Tmap.put(2, "Nagar");
Tmap.put(6, "Prakash");
System.out.println("The Size of TreeMap is : " + Tmap.size());
System.out.println(Tmap);
Tmap.clear();
System.out.println("The Size of TreeMap after delete is : "
+ Tmap.size());
}
}
Output:
| The Size of TreeMap is : 5
{1=Singh, 2=Nagar, 3=Kumar, 4=Kumar, 6=Prakash} The Size of TreeMap after delete is : 0 |

[ 0 ] Comments