โ— Shell
clean mode source โ†—

String.strip() vs trim()

Code Comparison

// trim() only removes ASCII whitespace
// (chars <= U+0020)
String clean = str.trim();
// strip() removes all Unicode whitespace
String clean = str.strip();
String left  = str.stripLeading();
String right = str.stripTrailing();

Why the modern way wins

๐ŸŒ

Unicode-correct

Handles all whitespace characters from every script.

๐ŸŽฏ

Directional

stripLeading() and stripTrailing() for one-sided trimming.

๐Ÿ›ก๏ธ

Fewer bugs

No surprise whitespace left behind in international text.

JDK Support

String.strip() vs trim()

Available

Widely available since JDK 11 (Sept 2018)

How it works

trim() only removes characters โ‰ค U+0020 (ASCII control chars and space). strip() uses Character.isWhitespace() which handles Unicode spaces like non-breaking space, ideographic space, etc.

Related Documentation

Proof