September 2019
Intermediate to advanced
816 pages
18h 47m
English
Removal from a Map can be accomplished by a key, or by a key and value.
For example, let's assume that we have the following Map:
Map<Integer, String> map = new HashMap<>();map.put(1, "postgresql");map.put(2, "mysql");map.put(3, "derby");
Removal by key is as simple as calling the V Map.remove(Object key) method. If the entry corresponding to the given key is successfully removed, then this method returns the associated value, otherwise it returns null.
Check the following examples:
String r1 = map.remove(1); // postgresqlString r2 = map.remove(4); // null
Now, the map contains the following entries (the entry from key 1 was removed):
2=mysql, 3=derby
Starting with JDK 8, the Map interface was enriched with a new ...
Read now
Unlock full access