LongAdder: increment, add, and read the sum
Use `increment()` to count one, `add(long)` to apply a delta, and `sum()` to read the total. Learn how to merge partial totals and when the read gives an exact result.
CKTIS / Java
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Use `increment()` to count one, `add(long)` to apply a delta, and `sum()` to read the total. Learn how to merge partial totals and when the read gives an exact result.
`Long.equals` compares the values stored in `Long` objects. Unlike `==` between two references, it does not test object identity.
Compute a 32-bit hash code from a primitive `long` without boxing it, and see why different inputs can produce the same result.
Distinguish the bounds of `long` from methods that compare two values, then choose the right identity for a maximum or minimum reduction.
Long.max and Long.min select the greater or smaller of two long values. Long.MIN_VALUE and Long.MAX_VALUE define the type's bounds, rather than a comparison result.
Distinguish a missing key from a stored null, choose the right lookup method, and cache singleton instances only after construction succeeds.
Use `Map.compute` to apply the same function whether a key is present or absent. Return `null` from the function to remove the entry.
Create a user's list only when it is needed, and reuse that same list on subsequent calls for the user's key.
Check whether a map contains a key even when its value is `null`. Learn how `put` inserts or replaces a mapping and how that differs from conditional insertion.
Check whether any key maps to a given value, and see why the `WeakHashMap` example checks for a `null` value before calling `reachabilityFence(t3)`.
Map.Entry<K,V> represents one key-value pair. The getKey() method reads its key, while getValue() reads its value. An entry may be connected to a map or exist independently of one.
Map.Entry.getKey() returns the key of one map entry as a value of type K. It takes no arguments; distinguish the entry's key from its value.
Map.Entry.getValue() reads the value of one key–value pair. It takes no arguments and returns the type V specified by Map.Entry<K,V>.
Use `entrySet()` when you need both the key and its corresponding value on each pass through a loop. The method returns a view of the map, not a copy.
`Map.forEach` visits entries directly on a map. It passes two arguments to a `BiConsumer`: the key first, then the associated value.
Use `map.get(key)` to retrieve a stored value. If the map allows `null` values, the result alone cannot distinguish a missing key from one explicitly mapped to `null`.
Look up a key in a map. The fallback is returned only if there is no entry for the key, not if the key is explicitly mapped to `null`.
`Map.keySet()` returns a set of keys backed by the map. Changes to the map appear in the view, and removing a key through the view removes its mapping if removal is supported.
Use `Map.merge()` to store an initial value, combine it with an existing value, or remove the entry when the combining function returns `null`.
Store a value under a key and get back the previous value. Learn when a `null` result means the key was absent and when it means the key already mapped to `null`.
`Map.size()` returns the current number of key–value mappings as an `int`. Replacing the value for an existing key does not increase the size.
`Map.values()` returns a collection backed by the map. Iterate over it to sum counters without looking up their keys or dropping repeated values.
Use `find()` to search for successive regex matches, or `find(int start)` to restart the search at a specified input index.
After a successful regex match, read the whole matched text or the text captured by a specific group. Group 0 is the whole match.