Skip to main content

Posts

Showing posts with the label java treemap example

java treemap example

TreeMap:- TreeMap is a implemented class of map interface where elements store on the basis of key value pair and according to some sorting order of keys . Example1:- TestMap.java import java.util.*; class TestMap { public static void main(String[]args) { Map<Object,Object> m=new TreeMap<Object,Object>(); m.put(101,"Sumit"); m.put(104,"Sunita"); m.put(102,"Suman"); m.put(107,"Sonu"); Set s=m.entrySet(); Iterator itr=s.iterator(); System.out.println("Key   :::::::::Value"); while(itr.hasNext()) { Map.Entry me=(Map.Entry)itr.next(); System.out.println(me.getKey()+"    :::: "+me.getValue()); } } } Output:- Key :::::::::Value 101    :::: Sumit 102    :::: Suman 104    :::: Sunita 107    :::: Sonu Example2:- TestMap.java import java.util.*; class TestMap { public static void main(String[]args) { Map<Object,Object> m=new...