FIND YOUR NEXT FEW LINES

Results for “Java”

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

257 snippets foundClear filters
JavaPrecise numeric calculations

Parse an integer in another base

Java: Supply an explicit radix to Integer.parseInt.

Java✓ Tested
JavaNumbers & dates

Parse an integer safely

Handle invalid Java integer input with NumberFormatException.

Java✓ Tested
JavaScriptObjects & JSON

Parse JSON text

Read a JavaScript object from JSON text.

JavaScript✓ Tested
JavaStream transformations

Partition a collection by a predicate

Java: Use partitioningBy to retain both matching and nonmatching values.

Java✓ Tested
JavaScriptRegular expressions & URL encoding

Percent-encode one URL component

JavaScript: encodeURIComponent escapes a parameter value rather than a complete URL.

JavaScript✓ Tested
JavaQueues & collection operations

Preserve map insertion order

Java: Use LinkedHashMap when iteration should follow the order keys were first added.

Java✓ Tested
JavaScriptObject behavior & collections

Prevent runtime changes to top-level properties

JavaScript: Object.freeze prevents ordinary top-level mutations; Reflect.set reports the rejected update without throwing.

JavaScript✓ Tested
JavaGetting Started

Print a number with two decimal places

Java: Format a small decimal value consistently for display.

Java✓ Tested
JavaScriptGetting Started

Print a number with two decimal places

JavaScript: Format a small decimal value consistently for display.

JavaScript✓ Tested
JavaFile operations & binary data

Process a text file one line at a time

Java: Use a buffered reader to avoid loading a large file into memory.

Java✓ Tested
JavaText validation & formatting

Process the lines of an in-memory string

Java: Use String.lines to handle common line terminators without retaining them.

Java✓ Tested
JavaScriptPromises & iteration protocols

Produce a lazy sequence with a generator

JavaScript: A generator yields one value per iteration without building an intermediate array.

JavaScript✓ Tested