Java 11 added handy String helpers for whitespace and repetition.
System.out.println(" ".isBlank());
System.out.println(" hi ".strip() + "|");
System.out.println("ab".repeat(3));
"one\ntwo\nthree".lines().forEach(System.out::println);
true
hi|
ababab
one
two
three
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-07-26