forked from javaevolved/javaevolved.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-strip.json
More file actions
44 lines (44 loc) · 1.55 KB
/
string-strip.json
File metadata and controls
44 lines (44 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
{
"id": 30,
"slug": "string-strip",
"title": "String.strip() vs trim()",
"category": "strings",
"difficulty": "beginner",
"jdkVersion": "11",
"oldLabel": "Java 8",
"modernLabel": "Java 11+",
"oldApproach": "trim()",
"modernApproach": "strip()",
"oldCode": "// trim() only removes ASCII whitespace\n// (chars <= U+0020)\nString clean = str.trim();",
"modernCode": "// strip() removes all Unicode whitespace\nString clean = str.strip();\nString left = str.stripLeading();\nString right = str.stripTrailing();",
"summary": "Use Unicode-aware stripping with strip(), stripLeading(), stripTrailing().",
"explanation": "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.",
"whyModernWins": [
{
"icon": "🌐",
"title": "Unicode-correct",
"desc": "Handles all whitespace characters from every script."
},
{
"icon": "🎯",
"title": "Directional",
"desc": "stripLeading() and stripTrailing() for one-sided trimming."
},
{
"icon": "🛡️",
"title": "Fewer bugs",
"desc": "No surprise whitespace left behind in international text."
}
],
"support": {
"state": "available",
"description": "Widely available since JDK 11 (Sept 2018)"
},
"prev": "strings/string-isblank",
"next": "strings/string-repeat",
"related": [
"strings/string-formatted",
"strings/string-indent-transform",
"strings/string-chars-stream"
]
}