@@ -241,28 +241,45 @@ public static String trimWhitespace(String str) {
241
241
}
242
242
243
243
/**
244
- * Trim <i >all</i > whitespace from the given {@code String }:
244
+ * Trim <em >all</em > whitespace from the given {@code CharSequence }:
245
245
* leading, trailing, and in between characters.
246
- * @param str the {@code String} to check
247
- * @return the trimmed {@code String}
246
+ * @param text the {@code CharSequence} to check
247
+ * @return the trimmed {@code CharSequence}
248
+ * @since 5.3.22
249
+ * @see #trimAllWhitespace(String)
248
250
* @see java.lang.Character#isWhitespace
249
251
*/
250
- public static String trimAllWhitespace (String str ) {
251
- if (!hasLength (str )) {
252
- return str ;
252
+ public static CharSequence trimAllWhitespace (CharSequence text ) {
253
+ if (!hasLength (text )) {
254
+ return text ;
253
255
}
254
256
255
- int len = str .length ();
256
- StringBuilder sb = new StringBuilder (str .length ());
257
+ int len = text .length ();
258
+ StringBuilder sb = new StringBuilder (text .length ());
257
259
for (int i = 0 ; i < len ; i ++) {
258
- char c = str .charAt (i );
260
+ char c = text .charAt (i );
259
261
if (!Character .isWhitespace (c )) {
260
262
sb .append (c );
261
263
}
262
264
}
263
265
return sb .toString ();
264
266
}
265
267
268
+ /**
269
+ * Trim <em>all</em> whitespace from the given {@code String}:
270
+ * leading, trailing, and in between characters.
271
+ * @param str the {@code String} to check
272
+ * @return the trimmed {@code String}
273
+ * @see #trimAllWhitespace(CharSequence)
274
+ * @see java.lang.Character#isWhitespace
275
+ */
276
+ public static String trimAllWhitespace (String str ) {
277
+ if (str == null ) {
278
+ return null ;
279
+ }
280
+ return trimAllWhitespace ((CharSequence ) str ).toString ();
281
+ }
282
+
266
283
/**
267
284
* Trim leading whitespace from the given {@code String}.
268
285
* @param str the {@code String} to check
0 commit comments