@@ -163,6 +163,10 @@ public static boolean isNotEmpty( String str )
163
163
/**
164
164
* <p>Checks if a (trimmed) String is <code>null</code> or empty.</p>
165
165
*
166
+ * <p><strong>Note:</strong> In future releases, this method will no longer trim the input string such that it works
167
+ * complementary to {@link #isNotEmpty(String)}. Code that wants to test for whitespace-only strings should be
168
+ * migrated to use {@link #isBlank(String)} instead.</p>
169
+ *
166
170
* @param str the String to check
167
171
* @return <code>true</code> if the String is <code>null</code>, or
168
172
* length zero once trimmed
@@ -172,6 +176,62 @@ public static boolean isEmpty( String str )
172
176
return ( ( str == null ) || ( str .trim ().length () == 0 ) );
173
177
}
174
178
179
+ /**
180
+ * <p>
181
+ * Checks if a String is whitespace, empty ("") or null.
182
+ * </p>
183
+ *
184
+ * <pre>
185
+ * StringUtils.isBlank(null) = true
186
+ * StringUtils.isBlank("") = true
187
+ * StringUtils.isBlank(" ") = true
188
+ * StringUtils.isBlank("bob") = false
189
+ * StringUtils.isBlank(" bob ") = false
190
+ * </pre>
191
+ *
192
+ * @param str the String to check, may be null
193
+ * @return <code>true</code> if the String is null, empty or whitespace
194
+ * @since 1.5.2
195
+ */
196
+ public static boolean isBlank ( String str )
197
+ {
198
+ int strLen ;
199
+ if ( str == null || ( strLen = str .length () ) == 0 )
200
+ {
201
+ return true ;
202
+ }
203
+ for ( int i = 0 ; i < strLen ; i ++ )
204
+ {
205
+ if ( !Character .isWhitespace ( str .charAt ( i ) ) )
206
+ {
207
+ return false ;
208
+ }
209
+ }
210
+ return true ;
211
+ }
212
+
213
+ /**
214
+ * <p>
215
+ * Checks if a String is not empty (""), not null and not whitespace only.
216
+ * </p>
217
+ *
218
+ * <pre>
219
+ * StringUtils.isNotBlank(null) = false
220
+ * StringUtils.isNotBlank("") = false
221
+ * StringUtils.isNotBlank(" ") = false
222
+ * StringUtils.isNotBlank("bob") = true
223
+ * StringUtils.isNotBlank(" bob ") = true
224
+ * </pre>
225
+ *
226
+ * @param str the String to check, may be null
227
+ * @return <code>true</code> if the String is not empty and not null and not whitespace
228
+ * @since 1.5.2
229
+ */
230
+ public static boolean isNotBlank ( String str )
231
+ {
232
+ return !StringUtils .isBlank ( str );
233
+ }
234
+
175
235
// Equals and IndexOf
176
236
//--------------------------------------------------------------------------
177
237
0 commit comments