Java Examples

Browse Java examples

javaSnippet

CompareTo Orders By Code Unit

String.compareTo compares UTF-16 code units one position at a time, so uppercase letters sort before lowercase and prefixes yield a length difference.

javaSnippet

Strip ANSI Escape Sequences

Strip ANSI escape sequences from colored CLI output with one regex covering CSI, OSC, and two-byte controls, leaving plain text untouched.

javaSnippet

Zip Entry Size Budget Guard

Cap ZipInputStream entries with a streaming byte budget: declared sizes can be unknown, so count every read and abort the moment an entry overshoots.

javaSnippet

Current Working Directory

user.dir anchors relative paths for the whole JVM: Paths.get("").toAbsolutePath() lands on the same directory that System.getProperty("user.dir") reports.