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 URL for MySQL. If the mysql key is present in the map, then the JDBC URL should be computed based on the corresponding value, jdbc:mysql://192.168.0.50/customers_db. But if the mysql key is not present, then the JDBC URL should be null. In addition to this, if the result of our computation is null (the JDBC URL cannot be computed), then we want to remove this entry from the map.
This is a job for V computeIfPresent(K key, BiFunction<? super K,? ...
Read now
Unlock full access