ChronoUnit.DAYS.between — days between dates
ChronoUnit.DAYS.between(start, end) returns the number of complete days as a long. For LocalDate, it calculates the calendar-date difference; an end before the start produces a negative result.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
ChronoUnit.DAYS.between(start, end) returns the number of complete days as a long. For LocalDate, it calculates the calendar-date difference; an end before the start produces a negative result.
Read repeatable annotations as an array and test for a marker annotation. Distinguish inherited lookup from lookup restricted to the class declaration.
When you have the target type in a `Class<T>` variable, use `cast` to get a reference of type `T` to the same object. Use `isInstance` to check a non-null value before casting.
Look up a constructor by its exact parameter types, then create an object in a separate step. The example uses the public no-argument StringBuilder constructor without bypassing access checks.
Read the declared types of a direct superclass and interfaces, and see why the runtime class of an ordinary `ArrayList<String>` cannot reveal the `String` argument.
`Class.getName()` returns the name of the represented type. For ordinary classes and interfaces, this is the binary name; arrays use a different notation.
Get a readable type or exception label without package or enclosing-class names.
Use `Class.isInstance` when the target type is held in a `Class<?>` variable and you want to check an object before casting it.
Inspect an object's actual class in Java SE 21, read its name, find declared fields and constructors, and distinguish direct annotations from inherited ones.
Read a type's name, look up fields and methods declared directly on it, and create an instance with a selected constructor without confusing discovery with access.
Cleaner registers a cleanup action. Invoke it explicitly through Cleanable.clean(); automatic execution is a fallback mechanism.
CodingErrorAction controls how a charset decoder or encoder handles coding errors. REPORT exposes an error to the caller, while REPLACE substitutes the configured replacement and continues processing. Malformed input and unmappable characters have independently configured policies.
`Collection.isEmpty()` returns `true` when a collection has no elements and `false` otherwise. It does not change the collection.
Create a stream pipeline from a collection that can run in parallel. Learn why execution mode and result order are separate and when to measure performance.
Use `Collection.size()` to read a collection’s element count as an `int`. If you only need to know whether the collection is empty, use `isEmpty()` instead.
Collection.spliterator() returns an object for traversing collection elements and potentially partitioning the work. Learn the default implementation, size characteristics, and limitations around modification and concurrency.
Collections.reverseOrder creates a comparator reversing natural ordering or the ordering of a supplied comparator.
Sort an existing list by its elements’ natural order or by a comparator. Both overloads modify the same list and preserve the relative order of elements that compare as equal.
`Collections.swap` exchanges the elements at two indices in the same list. It does not create a new list and requires the list to support `set`.
Collections.synchronizedList adds synchronization to a list. Traversal and sequences of dependent operations require additional locking.
Wrap an existing map to synchronize individual method calls. When traversing a view, lock the returned map for the entire traversal, not the view itself.
Create streams from collections, distinguish execution mode from element order, and use `List::stream` to flatten nested lists.
Block writes through a list view without freezing the source. To keep later edits to the source out of the view, wrap a private copy instead.
Define a stream collector that creates working state, adds elements, merges partial results, and converts the state into a final value.