9:31 pm - Thursday July 19, 2018

TreeMap example program to remove all values using remove()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

/**
*@author :CandidJava.com
*@descriptions : This program explain the function and use of clear() method
*/
import java.util.TreeMap;

class EmptyTreeMap {
public static void main(String[] args) {
// creating TreeMap Object
TreeMap treeMap = new TreeMap();
treeMap.put("1", "One");
treeMap.put("2", "Two");
treeMap.put("3", "Three");
// to remove all the values from the map using clear() method
treeMap.clear();
System.out.println("Total key value pairs in TreeMap are : "
+ treeMap.size());
}
}

 

Output:

D:\CandidJava\Util\TreeMap>javac EmptyTreeMap.java

Note: EmptyTreeMap.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\TreeMap>java EmptyTreeMap

Total key value pairs in TreeMap are : 0    

 

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply