8:10 pm - Sunday September 23, 2018

TreeMap Example program using Get Size()

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

class GetSizeOfTreeMap {
public static void main(String[] args) {
// creating TreeMap Object
TreeMap treeMap = new TreeMap();
System.out.println("Size of TreeMap : " + treeMap.size());
treeMap.put("1", "One");
treeMap.put("2", "Two");
treeMap.put("3", "Three");
// size() method is used display all the elements from the Map
System.out
.println("Size of TreeMap after addition : " + treeMap.size());
// remove() method is used to remove a particular value from the Map
Object obj = treeMap.remove("2");
System.out.println("Size of TreeMap after removal : " + treeMap.size());
}
}

Output:

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

Note: GetSizeOfTreeMapExample.java uses unchecked or unsafe operati

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\TreeMap>java GetSizeOfTreeMapExample

Size of TreeMap : 0

Size of TreeMap after addition : 3

Size of TreeMap after removal : 2

 

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply