-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap_hash.java
More file actions
27 lines (24 loc) · 840 Bytes
/
Copy pathmap_hash.java
File metadata and controls
27 lines (24 loc) · 840 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
27
import java.util.*;
public class map_hash {
public static void main(String args[]) {
Map<Integer, String> map = new HashMap<Integer, String>();
map.put(1, "amit");
map.put(7, "naman");
map.put(3, "ajay");
map.put(5, "john");
System.out.println(map);
for(Map.Entry obj : map.entrySet()) {
System.out.println(obj.getKey() + " : " + obj.getValue());
}
System.out.println("NO Idea (-_-)");
map.entrySet()
.stream()
.sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
.forEach(System.out :: println);
System.out.println("Again no idea (-_-)");
map.entrySet()
.stream()
.sorted(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.forEach(System.out :: println);
}
}