-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashmaps.java
More file actions
33 lines (24 loc) · 841 Bytes
/
Hashmaps.java
File metadata and controls
33 lines (24 loc) · 841 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
28
29
30
31
32
33
import java.util.HashMap;
public class Hashmaps {
public static void main(String[] args) {
// Hashmap
HashMap<String, Double> map = new HashMap<>();
map.put("apple", 0.5);
map.put("orange", 0.75);
map.put("banana", 0.25);
map.put("coconut", 1.0);
//map.remove("apple")
//System.out.println(map.get("coconut"));
//System.out.println(map.containsKey("apple"));
// if(map.containsKey("apple")) {
// System.out.println(map.get("apple"));
// } else {
// System.out.println("Key not found.");
// }
//System.out.println(map.containsValue(1.0));
// System.out.println(map.size());
for(String key : map.keySet()) {
System.out.println(key + ": $" + map.get(key));
}
}
}