-
Notifications
You must be signed in to change notification settings - Fork 0
/
Concurrenthashmap.java
38 lines (36 loc) · 1.24 KB
/
Concurrenthashmap.java
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
package com.example.mypackage;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
public class Concurrenthashmap {
public static void main(String[] args) {
//Creating a concurrent hashmap
ConcurrentHashMap<Integer,String> map=new ConcurrentHashMap<>();
map.put(0,"Java");
map.put(1,"Python");
map.put(0,"C++");
map.put(3,"C");
map.remove(0,"C++");
map.replace(1,"Python","JS");
map.putIfAbsent(9, "Bootstrap");
System.out.println(map);
for(Map.Entry<Integer,String> entry:map.entrySet()){
System.out.println(entry.getKey()+" "+entry.getValue());
}
for(Integer key:map.keySet()){
System.out.println(key);
}
for(String value:map.values()){
System.out.println(value);
}
System.out.println(map.containsKey(1));
System.out.println(map.get(1));
System.out.println(map.size());
System.out.println(map.containsKey(1));
System.out.println(map.containsValue("JS"));
System.out.println(map.isEmpty());
map.clear();
System.out.println(map.isEmpty());
System.out.println(map);
System.out.println(map.size());
}
}