import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
public class Student {
//code for generating HashMap; sort using the String name
public static void main(String[] args) {
// TODO Auto-generated method stub
Map<String, Integer> map = new HashMap<String, Integer>();
Map<String, Integer> sorted = new TreeMap<>();
map.put("chitra", 30);
map.put("hari", 20);
map.put("abhi", 50);
System.out.println(map.size());
sorted.putAll(map);
for(Map.Entry<String, Integer> entry: sorted.entrySet()) {
System.out.println(entry.getKey() + " -->" + entry.getValue());
}
}
}
No comments:
Post a Comment