forked from javaevolved/javaevolved.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring-isblank.json
More file actions
44 lines (44 loc) · 1.35 KB
/
string-isblank.json
File metadata and controls
44 lines (44 loc) · 1.35 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": 29,
"slug": "string-isblank",
"title": "String.isBlank()",
"category": "strings",
"difficulty": "beginner",
"jdkVersion": "11",
"oldLabel": "Java 8",
"modernLabel": "Java 11+",
"oldApproach": "trim().isEmpty()",
"modernApproach": "isBlank()",
"oldCode": "boolean blank =\n str.trim().isEmpty();\n// or: str.trim().length() == 0",
"modernCode": "boolean blank = str.isBlank();\n// handles Unicode whitespace too",
"summary": "Check for blank strings with a single method call.",
"explanation": "isBlank() returns true if the string is empty or contains only whitespace, including Unicode whitespace characters that trim() misses.",
"whyModernWins": [
{
"icon": "📖",
"title": "Self-documenting",
"desc": "isBlank() says exactly what it checks."
},
{
"icon": "🌐",
"title": "Unicode-aware",
"desc": "Handles all Unicode whitespace, not just ASCII."
},
{
"icon": "⚡",
"title": "No allocation",
"desc": "No intermediate trimmed string is created."
}
],
"support": {
"state": "available",
"description": "Widely available since JDK 11 (Sept 2018)"
},
"prev": "collections/unmodifiable-collectors",
"next": "strings/string-strip",
"related": [
"strings/string-formatted",
"strings/string-strip",
"strings/string-indent-transform"
]
}