There's more...

ConcurrentHashMap has more methods than what's specified in the previous section. We enumerate some of them in the following list:

  • forEachKey() and forEachValue(): These methods are similar to the forEach() methods, but in this case, the expression processes the keys and values stored in ConcurrentHashMap, respectively.
  • searchEntries(), searchKeys(), and searchValues(): These methods are similar to the search() method explained before. However, in this case, the expression passed as a parameter receives an Entry object, a key, or a value of the elements stored in ConcurrentHashMap.
  • reduceEntries(), reduceKeys(), and reduceValues(): These methods are similar to the reduce() method explained before. However, in this case, the expression passed as a parameter receives an Entry object, a key, or a value of the elements stored in ConcurrentHashMap.
  • reduceXXXToDouble(), reduceXXXToLong(), and reduceXXXToInt(): These methods allow you to make a reduction of the elements of ConcurrentHashMap by generating a double, long, or int value, respectively.
  • computeIfPresent(): This method complements the computeIfAbsent() method. In this case, it receives a key and an implementation of the BiFunction interface that can be expressed as a lambda expression. If the key exists in the HashMap, the method applies the expression to calculate the new value of the key. The BiFunction interface receives the key and the actual value of that key as parameters, and it returns the new value.
  • merge(): This method receives a key, value, and implementation of the BiFunction interface that can be expressed as a lambda expression; they are received as parameters. If the key doesn't exist in ConcurrentHashMap, it inserts it there and associates the value parameter with it. If it exists, execute BiFunction to calculate the new value associated with the key. The BiFunction interface receives the key and its actual value as parameters and returns the new value associated with the key.
  • getOrDefault(): This method receives a key and a default value as parameters. If the key exists in ConcurrentHashMap, it returns its associated value. Otherwise, it returns the default value.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.172.200