-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashMapKeyAndValue.java
More file actions
41 lines (30 loc) · 1.07 KB
/
HashMapKeyAndValue.java
File metadata and controls
41 lines (30 loc) · 1.07 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.HashMap;
import java.util.Map;
/**
* Created by pranikchainani on 8/6/16.
*/
public class HashMapKeyAndValue {
public static void printKeys(String keys, Integer value){
System.out.println(keys +" -> "+value);
}
public static void main(String[] args) {
Map<String, Integer> nameAndAge = new HashMap<>();
nameAndAge.put("Karthikk",24);
nameAndAge.put("Chandan",35);
nameAndAge.put("Pranick",14);
nameAndAge.put("Gaarthick",24);
// Set<String> keySet = nameAndAge.keySet();
// System.out.println(keySet);
// for (String key:keySet){
// System.out.println(key + "->" +nameAndAge.get(key));
// }
// Collection<Integer> valuesSet = nameAndAge.values();
// System.out.println(valuesSet);
// Lambda Programming
// nameAndAge.keySet()
// .forEach(key -> printKeys(key, nameAndAge.get(key)));
//
// nameAndAge.forEach( (key, value) -> printKeys(key,value));
nameAndAge.forEach(HashMapKeyAndValue::printKeys);
}
}