Parsing, creating, and formatting dates and date-times in Java
Build dates from fields, parse ISO or custom text, and format dates and date-times without assigning a time zone.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Build dates from fields, parse ISO or custom text, and format dates and date-times without assigning a time zone.
Build local dates and times from fixed inputs, find the Monday of the same ISO week, and choose the overload that returns the type you need.
Create a local date-time with `LocalDateTime.of`, then add hours or minutes without changing the original value.
Track a running `long` maximum with `LongAccumulator`, choose an identity that works for your input range, and understand what `get()` can report during concurrent updates.
Use `LongAdder` to collect statistics updated by multiple threads. Learn which methods change the total, when a read is exact, and why `sumThenReset()` does not create an atomic boundary between reporting intervals.
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`.