mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8200436: String::isBlank
Reviewed-by: sundar
This commit is contained in:
parent
003b10c2bc
commit
a455811dca
2 changed files with 99 additions and 0 deletions
|
@ -2728,6 +2728,31 @@ public final class String
|
|||
return ret == null ? this : ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code true} if the string is empty or contains only
|
||||
* {@link Character#isWhitespace(int) white space} codepoints,
|
||||
* otherwise {@code false}.
|
||||
*
|
||||
* @return {@code true} if the string is empty or contains only
|
||||
* {@link Character#isWhitespace(int) white space} codepoints,
|
||||
* otherwise {@code false}
|
||||
*
|
||||
* @see Character#isWhitespace(int)
|
||||
*
|
||||
* @since 11
|
||||
*/
|
||||
public boolean isBlank() {
|
||||
return indexOfNonWhitespace() == length();
|
||||
}
|
||||
|
||||
private int indexOfNonWhitespace() {
|
||||
if (isLatin1()) {
|
||||
return StringLatin1.indexOfNonWhitespace(value);
|
||||
} else {
|
||||
return StringUTF16.indexOfNonWhitespace(value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This object (which is already a string!) is itself returned.
|
||||
*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue