-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathstring-isblank.yaml
More file actions
43 lines (43 loc) · 1.28 KB
/
string-isblank.yaml
File metadata and controls
43 lines (43 loc) · 1.28 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
---
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 =
str.trim().isEmpty();
// or: str.trim().length() == 0
modernCode: |-
boolean blank = str.isBlank();
// 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"
docs:
- title: "String.isBlank()"
href: "https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/lang/String.html#isBlank()"