-
-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathHashMapExample.java
More file actions
47 lines (32 loc) · 860 Bytes
/
Copy pathHashMapExample.java
File metadata and controls
47 lines (32 loc) · 860 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
41
42
43
44
45
46
47
package util;
import java.util.HashMap;
/**
* Created by nikoo28 on 8/14/22 10:19 PM
*/
public class HashMapExample {
public static void main(String[] args) {
// Create a HashMap
HashMap<String, Integer> fruitPricesMap = new HashMap<>();
// Add values
fruitPricesMap.put("Apple", 10);
fruitPricesMap.put("Banana", 40);
// Print
System.out.println(fruitPricesMap);
fruitPricesMap.put("Mango", 50);
// Print
System.out.println(fruitPricesMap);
// Update
fruitPricesMap.put("Apple", 15);
// Print
System.out.println(fruitPricesMap);
// Remove
fruitPricesMap.remove("Banana");
// Print
System.out.println(fruitPricesMap);
// Check
if (fruitPricesMap.containsKey("Mango"))
System.out.println("PRESENT");
else
System.out.println("NOT PRESENT");
}
}