String.strip() vs trim()
Use Unicode-aware stripping with strip(), stripLeading(), stripTrailing().
Porównanie kodu
✕ 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ć.
Dlaczego nowoczesne podejście wygrywa
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
Wsparcie JDK
String.strip() vs trim()
Dostępne
Widely available since JDK 11 (Sept 2018)
Jak to działa
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.
Powiązana dokumentacja