StringUtils.hasLength()
时间: 2024-05-05 08:15:24 浏览: 202
StringUtils
4星 · 用户满意度95%
The StringUtils.hasLength() method is a static method of the StringUtils class in the Apache Commons Lang library.
It takes a String as its parameter and checks if the string is not null and has a length greater than 0. If the string is null or has a length of 0, the method returns false. Otherwise, it returns true.
Here's an example:
```
String str1 = null;
String str2 = "";
String str3 = "hello world";
StringUtils.hasLength(str1); // returns false
StringUtils.hasLength(str2); // returns false
StringUtils.hasLength(str3); // returns true
```
This method is useful when checking if a string is not empty or null before performing operations on it.
阅读全文