-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
40 lines (25 loc) · 1019 Bytes
/
Main.java
File metadata and controls
40 lines (25 loc) · 1019 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
34
35
36
37
38
39
40
package Hashmaps;
import java.util.HashMap;
public class Main {
public static void main(String[] args){
// hashmap is a data structure that stores key-value pairs
// keys are unique, but values can be repetitive
// does not maintain order but is memory efficient
// HashMap<key, value>
HashMap<String, Integer> hashMap = new HashMap<>();
hashMap.put("litchi", 200);
hashMap.put("pineapple", 60);
hashMap.put("banana", 50);
hashMap.put("apple", 100);
hashMap.remove("apple");
System.out.println(hashMap);
System.out.println(hashMap.get("litchi"));
System.out.println(hashMap.containsKey("banana"));
System.out.println(hashMap.containsValue(200));
System.out.println(hashMap.size());
for (String key : hashMap.keySet()){
System.out.println(key + " ₹" + hashMap.get(key));
}
// hashMap.put("Litchi", 300); // overwrite the value not error
}
}