StringUtils.isEmpty
时间: 2023-11-17 13:08:14 浏览: 77
StringUtils.isEmpty is a method in the Apache Commons Lang library that checks whether a given string is empty or null. The method returns true if the string is null or has zero length, otherwise it returns false.
For example, consider the following code snippet:
```
String str1 = "";
String str2 = null;
String str3 = "Hello World";
boolean isEmpty1 = StringUtils.isEmpty(str1); // true
boolean isEmpty2 = StringUtils.isEmpty(str2); // true
boolean isEmpty3 = StringUtils.isEmpty(str3); // false
```
In this example, StringUtils.isEmpty returns true for str1 and str2, which are empty or null, and false for str3, which contains a non-empty string. By using this method, we can easily check whether a string is empty or null before performing any operations on it.
阅读全文