ConcurrentHashMapmap = new ConcurrentHashMap<>(); map.put("A", 1); map.put("B", 2); Integer removedValue = map.remove("B"); System.out.println("Removed Value: " + removedValue); // Output: Removed Value: 2 System.out.println("Concurrent Map After Removing B: " + map); // Output: Concurrent Map After Removing B: {A=1}
ConcurrentHashMapThe ConcurrentMap interface is part of the java.util.concurrent package library, along with other concurrency utilities like Executors, Locks, and Atomic classes.map = new ConcurrentHashMap<>(); map.put("A", 1); map.put("B", 2); Integer removedValue = map.remove("A", 1); // Only remove if the key-value pair match System.out.println("Removed Value: " + removedValue); // Output: Removed Value: 1 System.out.println("Concurrent Map After Removing A: " + map); // Output: Concurrent Map After Removing A: {B=2}