src/java.base/share/classes/java/lang/String.java
changeset 50175 589ed2770141
parent 50098 92560438d306
child 50215 2fb27c352cae
--- a/src/java.base/share/classes/java/lang/String.java	Wed May 16 15:25:51 2018 +0200
+++ b/src/java.base/share/classes/java/lang/String.java	Fri May 18 08:43:49 2018 -0300
@@ -2729,6 +2729,31 @@
     }
 
     /**
+     * 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.
      *
      * @return  the string itself.