Tests if a CharSequence is null, empty, or contains only whitespace. @param s the CharSequence to check @return true if a CharSequence is null, empty, or contains only whitespace
(final CharSequence s)
| 105 | * @return true if a CharSequence is null, empty, or contains only whitespace |
| 106 | */ |
| 107 | public static boolean isBlank(final CharSequence s) { |
| 108 | if (s == null) { |
| 109 | return true; |
| 110 | } |
| 111 | |
| 112 | final int length = s.length(); |
| 113 | if (length == 0) { |
| 114 | return true; |
| 115 | } |
| 116 | |
| 117 | for (int i = 0; i < length; i++) { |
| 118 | if (!Character.isWhitespace(s.charAt(i))) { |
| 119 | return false; |
| 120 | } |
| 121 | } |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Tests if a CharSequence is NOT null, empty, or contains only whitespace. |