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

Convert known numeric text to an integer

Java: Convert a trusted literal to an integer before adding. Validate external input before converting it.

Java✓ Tested
JavaScriptGetting Started

Convert known numeric text to an integer

JavaScript: Convert a trusted literal to an integer before adding. Validate external input before converting it.

JavaScript✓ Tested
JavaFile operations & binary data

Copy a file without replacing an existing destination

Java: Files.copy fails if the destination already exists unless replacement is explicitly enabled.

Java✓ Tested
JavaScriptArray traversal & selection

Copy a range without changing the source

JavaScript: Array.slice returns a shallow copy of the selected half-open range.

JavaScript✓ Tested
JavaScriptObject behavior & collections

Copy nested structured data independently

JavaScript: structuredClone creates an independent copy of supported structured values.

JavaScript✓ Tested
JavaDates & time zones

Count days between two dates

Java: Use ChronoUnit.DAYS for an elapsed count rather than a Period day component.

Java✓ Tested
JavaScriptUTC date operations

Count days between UTC-midnight dates

JavaScript: A day is exactly 86400000 milliseconds for these explicitly UTC-midnight inputs.

JavaScript✓ Tested
JavaGetting Started

Count the items in a collection

Java: Read the collection’s length instead of hard-coding the loop limit.

Java✓ Tested
JavaScriptGetting Started

Count the items in a collection

JavaScript: Read the collection’s length instead of hard-coding the loop limit.

JavaScript✓ Tested
JavaText validation & formatting

Count Unicode code points

Java: Use codePointCount when supplementary characters should count as one rather than two UTF-16 units.

Java✓ Tested
JavaScriptText handling & Unicode

Count Unicode code points in a string

JavaScript: String iteration combines surrogate pairs, unlike the UTF-16 length property.

JavaScript✓ Tested
JavaCollections

Count word frequencies

Use Map.merge to count repeated words in Java.

Java✓ Tested