fork download
  1.  
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.Map.Entry;
  7.  
  8. class Demo {
  9.  
  10. public static void main(String a[]){
  11. TreeMap<String, String> hm = new TreeMap<String, String>();
  12. //add key-value pair to TreeMap
  13. hm.put("first", "FIRST INSERTED");
  14. hm.put("second", "SECOND INSERTED");
  15. hm.put("third","THIRD INSERTED");
  16. System.out.println(hm);
  17. //getting value for the given key from TreeMap
  18. Set<Entry<String, String>> entires = hm.entrySet();
  19. for(Entry<String,String> ent:entires){
  20. System.out.println(ent.getKey()+" ==> "+ent.getValue());
  21. }
  22. }
  23. }
Success #stdin #stdout 0.06s 3359744KB
stdin
Standard input is empty
stdout
{first=FIRST INSERTED, second=SECOND INSERTED, third=THIRD INSERTED}
first ==> FIRST INSERTED
second ==> SECOND INSERTED
third ==> THIRD INSERTED