FIND YOUR NEXT FEW LINES

Results for “Java”

Small, practical examples. Search by task or narrow things down below.

257 snippets foundClear filters
JavaGetting Started

Store a value in a named variable

Java: Give a value a descriptive name and print it.

Java✓ Tested
JavaScriptGetting Started

Store a value in a named variable

JavaScript: Give a value a descriptive name and print it.

JavaScript✓ Tested
JavaNumbers & dates

Sum integer values

Reduce a Java integer stream to its sum.

Java✓ Tested
JavaScriptArrays

Sum numeric values

Provide an initial accumulator for JavaScript reduce, including empty arrays.

JavaScript✓ Tested
JavaStream transformations

Take a page from a stream

Java: Use skip and limit with a known stable input order.

Java✓ Tested
JavaQueues & collection operations

Take an immutable list snapshot

Java: List.copyOf protects the snapshot from later changes to the source list.

Java✓ Tested
JavaScriptPromises & iteration protocols

Transform a resolved promise result

JavaScript: A then handler returns the value passed to the next promise in the chain.

JavaScript✓ Tested
JavaRecords & reliable control flow

Transform an asynchronous result

Java: Chain thenApply and join a CompletableFuture to retrieve the completed value.

Java✓ Tested
JavaRecords & reliable control flow

Transform an optional value

Java: Use Optional.map and orElse to transform a possibly absent result.

Java✓ Tested
JavaScriptArrays

Transform array values

Use map to create a JavaScript array of squared values.

JavaScript✓ Tested
JavaScriptText handling & Unicode

Transform each regex match with a callback

JavaScript: A replacement callback computes the replacement separately for each match.

JavaScript✓ Tested
JavaStream transformations

Transform each stream value

Java: Use map to turn each input into a corresponding output.

Java✓ Tested