FIND YOUR NEXT FEW LINES

Results for “Java”

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

257 snippets foundClear filters
JavaScriptNumbers & numeric validation

Validate a finite numeric value without coercion

JavaScript: Number.isFinite rejects numeric strings as well as NaN and infinity.

JavaScript✓ Tested
JavaRecords & reliable control flow

Validate a required argument

Java: Use requireNonNull with a useful message at an API boundary.

Java✓ Tested
JavaScriptRegular expressions & URL encoding

Validate a whole ASCII identifier

JavaScript: Use an anchored expression without the multiline flag and reject a trailing line break explicitly.

JavaScript✓ Tested
JavaGetting Started

Visit every item in a collection

Java: Print each element in the collection’s original order.

Java✓ Tested
JavaScriptGetting Started

Visit every item in a collection

JavaScript: Print each element in the collection’s original order.

JavaScript✓ Tested
JavaFile operations & binary data

Visit files recursively

Java: Close the stream returned by Files.walk and sort relative paths for stable output.

Java✓ Tested
JavaScriptFiles & async

Wait for multiple promises

Use Promise.all to collect JavaScript results in input order.

JavaScript✓ Tested
JavaFiles & paths

Write a UTF-8 file

Write a Java string to a file using an explicit text encoding.

Java✓ Tested
JavaScriptFiles & async

Write a UTF-8 file

Use the built-in Node.js filesystem API to save text.

JavaScript✓ Tested
JavaFile operations & binary data

Write and read binary bytes

Java: Use the byte-oriented Files methods when text encoding should not be involved.

Java✓ Tested
JavaEncoding & structured values

Write and read typed binary fields

Java: Data streams use a matching write/read order and fixed encodings for Java primitive values.

Java✓ Tested
TypeScriptUTC date operations

Convert epoch milliseconds to whole seconds

TypeScript: JavaScript Date stores milliseconds while many APIs use Unix seconds.

TypeScript✓ Tested