Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

Knowledge base — Java

Programming syntax, operators and concepts. Find an explanation, explore an example and return to learning.

Entries: 813

Java

Set membership and cycle detection

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.

Advanced · Java SE 21
Java

SoftReference — a soft reference

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.

Intermediate · Java SE 21; repository runtime, production runtime not attested
Java

Encoding Java strings as UTF-8 and UTF-16BE

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.

Advanced · Java SE 21
Java

Stream.allMatch: practical reference

Stream.allMatch: practical reference: Stream.allMatch(predicate) is a short-circuiting terminal operation that returns true when every encountered element satisfies the predicate.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.anyMatch: practical reference

Stream.anyMatch: practical reference: Stream.anyMatch(predicate) is a short-circuiting terminal operation that returns true when at least one element satisfies the predicate.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.collect: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.count: practical reference

Stream.count: practical reference: Stream.count is a terminal reduction returning as a long the number of elements reaching that point in the pipeline.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.distinct: practical reference

Stream.distinct: practical reference: Stream.distinct is a stateful intermediate operation that removes duplicates according to Object.equals.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.dropWhile: practical reference

Stream.dropWhile: practical reference: Stream.dropWhile(predicate) is a stateful intermediate operation that removes the longest matching prefix from an ordered stream.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.filter: practical reference

Stream.filter: practical reference: Stream.filter(predicate) is a stateless intermediate operation that passes only elements for which the predicate returns true.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.findAny: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.findFirst: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.flatMap: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.forEach: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Preserve encounter order with Stream.forEachOrdered

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.

Intermediate · Java SE 21
Java

Stream.limit: practical reference

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.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.map: practical reference

Stream.map: practical reference: map is a stateless one-to-one intermediate operation that lazily applies a Function to each consumed element and produces a stream of results.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.mapMulti: practical reference

Stream.mapMulti: practical reference: mapMulti is a one-to-zero-or-many intermediate operation whose mapper sends each result to a supplied Consumer instead of creating a separate stream.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.max: practical reference

Stream.max: practical reference: max is a terminal reduction that returns the greatest stream element under the supplied Comparator, or Optional.empty for an empty stream.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Java

Stream.min: practical reference

Stream.min: practical reference: min is a terminal reduction that returns the least stream element under the supplied Comparator, or Optional.empty for an empty stream.

Intermediate · Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime