September 2019
Intermediate to advanced
816 pages
18h 47m
English
Let's suppose that we have the following Map:
Map<String, String> map = new HashMap<>();map.put("postgresql", "127.0.0.1");map.put("mysql", "192.168.0.50");
We use this map to build JDBC URLs for different database types.
Let's assume that we want to build the JDBC URLs for MySQL and Derby DB. In this case, irrespective of whether the key (mysql or derby) is present in the map, the JDBC URL should be computed based on the corresponding key and value (which can be null). In addition, if the key is present in the map and the result of our computation is null (the JDBC URL cannot be computed), then we want to remove this entry from the map. Basically, this is a combination of computeIfPresent() and computeIfAbsent().