Results for “Java”
Small, practical examples. Search by task or narrow things down below.
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
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
Copy a file without replacing an existing destination
Java: Files.copy fails if the destination already exists unless replacement is explicitly enabled.
Java✓ Tested
Copy a range without changing the source
JavaScript: Array.slice returns a shallow copy of the selected half-open range.
JavaScript✓ Tested
Copy nested structured data independently
JavaScript: structuredClone creates an independent copy of supported structured values.
JavaScript✓ Tested
Count days between two dates
Java: Use ChronoUnit.DAYS for an elapsed count rather than a Period day component.
Java✓ Tested
Count days between UTC-midnight dates
JavaScript: A day is exactly 86400000 milliseconds for these explicitly UTC-midnight inputs.
JavaScript✓ Tested
Count the items in a collection
Java: Read the collection’s length instead of hard-coding the loop limit.
Java✓ Tested
Count the items in a collection
JavaScript: Read the collection’s length instead of hard-coding the loop limit.
JavaScript✓ Tested
Count Unicode code points
Java: Use codePointCount when supplementary characters should count as one rather than two UTF-16 units.
Java✓ Tested
Count Unicode code points in a string
JavaScript: String iteration combines surrogate pairs, unlike the UTF-16 length property.
JavaScript✓ Tested
Count word frequencies
Use Map.merge to count repeated words in Java.
Java✓ Tested