There probably is a method to return the index of the first non-blank char in a String in Java5/6. But I cannot find it any more. A code anylizing tool says it is better than checking String.trim().length()
.
Java 11 introduces the "isBlank" method. See https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/String.html#isBlank()
Returns true if the string is empty or contains only white space codepoints, otherwise false.
I always like to use the Apache Commons StringUtils library. It has isEmpty() and is isBlank() which handles whitespace.
http://commons.apache.org/lang/api-2.5/org/apache/commons/lang/StringUtils.html
Not to mention the numerous other helpful methods in that class and the library in general.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With