Strings Początkujący

Use Unicode-aware stripping with strip(), stripLeading(), stripTrailing().

✕ Java 8
// trim() only removes ASCII whitespace
// (chars <= U+0020)
String clean = str.trim();
✓ Java 11+
// strip() removes all Unicode whitespace
String clean = str.strip();
String left  = str.stripLeading();
String right = str.stripTrailing();
Widzisz problem z tym kodem? Daj nam znać.
🌐

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.

Stare podejście
trim()
Nowoczesne podejście
strip()
Od JDK
11
Poziom trudności
Początkujący
String.strip() vs trim()
Dostępne

Widely available since JDK 11 (Sept 2018)

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.

Udostępnij 𝕏 🦋 in