Scanner.useLocale — set the locale for reading numbers
Set the locale for one scanner so it reads numbers using the conventions of the input, such as a comma as the decimal separator.
CKTIS / Knowledge base
Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.
Set the locale for one scanner so it reads numbers using the conventions of the input, such as a comma as the decimal separator.
SecureRandom generates cryptographically strong random values. nextBytes fills the supplied byte array.
Learn when a semaphore waits for a permit, why `tryAcquire()` differs from `tryAcquire(0)`, and how to avoid adding extra permits during cleanup.
`Set.add` returns `true` when it inserts an element and `false` when an equivalent element is already present. `HashSet` and `TreeSet` identify duplicates differently.
Check whether a set has an element equal to the object you supply, and see why a newly created instance with the same ID can match.
Test, add, and remove members of a `Set`. Use the result of `add` to detect a type already on the active path, and use `finally` to remove its entry when the call exits.
`Set.size()` returns how many elements the set currently holds, not how many times you tried to add one.
SoftReference<T> in java.lang.ref holds a soft reference to an object. Once the object is no longer strongly reachable, the garbage collector may clear that reference in response to memory demand. Reading it through get() requires handling null.
`firstKey()` and `lastKey()` return the keys at the ends of the map’s sort order. Both throw `NoSuchElementException` if the map is empty.
Learn when an optimistic read can be trusted and how to retry under a shared read lock using the correct stamp to release it.
Use `String.getBytes(Charset)` to encode text as bytes. See why `Euro €` takes 8 bytes in UTF-8 and 12 in UTF-16BE, and why UTF-16BE does not always use two bytes per code point.
Stream.allMatch: practical reference: Stream.allMatch(predicate) is a short-circuiting terminal operation that returns true when every encountered element satisfies the predicate.
Stream.anyMatch: practical reference: Stream.anyMatch(predicate) is a short-circuiting terminal operation that returns true when at least one element satisfies the predicate.
Stream.collect: practical reference: Stream.collect is a terminal mutable reduction that accumulates elements into a container through a Collector or through supplier, accumulator, and combiner functions.
Stream.count: practical reference: Stream.count is a terminal reduction returning as a long the number of elements reaching that point in the pipeline.
Stream.distinct: practical reference: Stream.distinct is a stateful intermediate operation that removes duplicates according to Object.equals.
Stream.dropWhile: practical reference: Stream.dropWhile(predicate) is a stateful intermediate operation that removes the longest matching prefix from an ordered stream.
Stream.filter: practical reference: Stream.filter(predicate) is a stateless intermediate operation that passes only elements for which the predicate returns true.
Stream.findAny: practical reference: findAny is a short-circuiting terminal operation that returns an Optional containing some stream element, or an empty Optional for an empty stream.
Stream.findFirst: practical reference: findFirst is a short-circuiting terminal operation that returns the first element in encounter order for an ordered stream, or Optional.empty when empty.
Stream.flatMap: practical reference: flatMap is a one-to-many intermediate operation that replaces each element with the contents of a mapper-produced stream and flattens those results.
Stream.forEach: practical reference: forEach is a terminal operation that invokes a Consumer for every element but explicitly does not guarantee encounter order in a parallel pipeline.
Use `forEachOrdered` when a terminal action must follow the stream’s encounter order, even in a parallel pipeline. Ordinary `forEach` does not make that guarantee in parallel mode.
Stream.limit: practical reference: limit is a short-circuiting stateful intermediate operation that yields at most maxSize elements, taking the first elements for an ordered stream.