2:31 am - Tuesday November 13, 2018

TreeMap example program using SubMap()

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

class GetSubMapFromTreeMap {
public static void main(String[] args) {
// creating TreeMap Object
TreeMap treeMap = new TreeMap();
treeMap.put("1", "One");
treeMap.put("3", "Three");
treeMap.put("2", "Two");
treeMap.put("5", "Five");
treeMap.put("4", "Four");
// subMap() method is called
SortedMap sortedMap = treeMap.subMap("2", "5");
System.out.println("SortedMap Contains : " + sortedMap);
}
}

Output:

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

Note: GetSubMapFromTreeMap.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

D:\CandidJava\Util\TreeMap>java GetSubMapFromTreeMap

SortedMap Contains : {2=Two, 3=Three, 4=Four}

BACK

Filed in: Z-A All Java Codes

No comments yet.

Leave a Reply