Results for “Java”
Small, practical examples. Search by task or narrow things down below.
Calculate differences between adjacent readings
JavaScript: Slice off the first value and compare each remaining value with its predecessor.
JavaScript✓ Tested
Calculate integers beyond Number’s precise range
JavaScript: Use BigInt operands together to avoid precision loss.
JavaScript✓ Tested
Calculate several numeric stream statistics
Java: Use summaryStatistics to calculate count, sum, minimum, maximum, and average in one pass.
Java✓ Tested
Call a library function
Java: Use a standard absolute-value function with a small negative number.
Java✓ Tested
Call a library function
JavaScript: Use a standard absolute-value function with a small negative number.
JavaScript✓ Tested
Check a filename suffix
Java: Use endsWith for a case-sensitive literal suffix test.
Java✓ Tested
Check a string prefix
Java: Use startsWith to check a literal Java prefix without a regular expression.
Java✓ Tested
Check any and all stream elements
Java: Use short-circuiting match operations for predicates over a Java collection.
Java✓ Tested
Check array membership with includes
JavaScript: includes uses SameValueZero comparison, which also matches NaN.
JavaScript✓ Tested
Check for a substring
Perform a case-sensitive JavaScript substring check.
JavaScript✓ Tested
Check the Gregorian leap-year rule
Java: Use Year.isLeap rather than checking divisibility by four alone.
Java✓ Tested
Check whether a value is a safe integer
JavaScript: Number.isSafeInteger also checks the exact-integer range supported by Number.
JavaScript✓ Tested