import java.util.SortedMap; import java.util.TreeMap; public class Test { public static void main(String[] args) { TreeMap<Integer,String> map = new TreeMap<Integer,String>(); map.put(1, "one"); map.put(2, "two"); map.put(3, "three"); map.put(4, "four"); SortedMap<Integer, String> smap1 = map.tailMap(2); SortedMap<Integer, String> smap2 = smap1.headMap(4); SortedMap<Integer, String> smap3 = smap2.subMap(2, 3); System.out.println(smap3); } }
import java.util.TreeMap;
public class Test {
public static void main(String[] args) {
TreeMap<Integer,String> map = new TreeMap<Integer,String>();
map.put(1, "one");
map.put(2, "two");
map.put(3, "three");
map.put(4, "four");
SortedMap<Integer, String> smap1 = map.tailMap(2);
SortedMap<Integer, String> smap2 = smap1.headMap(4);
SortedMap<Integer, String> smap3 = smap2.subMap(2, 3);
System.out.println(smap3);
}
headMap: returns a view of the portion of this map whose keys are less than (or equal to, if is true) to the given key.
subMap: returns a view of the portion of this map whose keys range from to (where to value is exclusive).
Oracle Certified Professional Java Programmer
Access: Public Instant Grading
Jobilize.com uses cookies to ensure that you get the best experience. By continuing to use Jobilize.com web-site, you agree to the Terms of Use.