7:54 pm - Tuesday April 23, 2019

TreeMap example program to remove particular element using remove()

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 remove() method
import java.util.TreeMap;

class RemoveValueFromTreeMap {
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");
// remove() method is used to remove a particular value from the Map
Object obj = treeMap.remove("2");
System.out.println(obj + " Removed from TreeMap");


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

Note: RemoveValueFromTreeMap.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\TreeMap>java RemoveValueFromTreeMap

Two Removed from TreeMap


Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply