使用 Java 检测 Null 或者为空或仅包含空白字符的字符串。
我们可以使用 String 类中的 isEmpty()方法来验证给定字符串是否为空。只有当 length() 为 0 时,此方法才返回 true。
示例
import java.lang.*;
public class StringDemo {
public static void main(String[] args) {
String str = "tutorialspoint";
// prints length of string
System.out.println("length of string = " + str.length());
// checks if the string is empty or not
System.out.println("is this string empty? = " + str.isEmpty());
}
}输出
length of string = 14 is this string empty? = false
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP