-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMapHierarchy.java
More file actions
26 lines (21 loc) · 804 Bytes
/
Copy pathMapHierarchy.java
File metadata and controls
26 lines (21 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package array;
import java.util.Comparator;
import java.util.Map;
import java.util.TreeMap;
import java.util.Map.Entry;
public class MapHierarchy {
public static void main(String[] args) {
Comparator<Student> com=(s1,s2)->s1.age>s2.age?1:s1.age<s2.age?-1:0;
Map<Student, String> map=new TreeMap<Student, String>(com);
map.put(new Student("ramesh", 23), "jalna");
map.put(new Student("abhijeet", 22), "Parbhani");
map.put(new Student("shubham", 24), "beed");
map.put(new Student("krishna", 21), "solapur");
map.put(new Student("aditya", 22), "dharashiv");
for(Student st:map.keySet()) {
System.out.println(map.get(st));
//System.out.println(map.putIfAbsent(new Student("krishna", 21), "pune"));
}
System.out.println(map.values());
}
}