In Java's default built-in library, there is no utility method like the one you asked. You can implement it yourself You can use the StringUtils class that belongs to the Apache commons library.
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
If you want to check with blank characters, you can use String.isBlank method.
StringUtils.isBlank(null) = true
StringUtils.isBlank("") = true
StringUtils.isBlank(" ") = true
StringUtils.isBlank("bob") = false
StringUtils.isBlank(" bob ") = false
I think you can use isEmpty and isBlank method of StringUtils class. isEmpty returns whether the string is null or not, and isBlank returns true if the string is filled with only spaces.
© 2024 OneMinuteCode. All rights reserved.