如何测试String是否为null或空?
我们可以使用字符串类的isEmpty()方法验证给定的字符串是否为空。此方法仅在长度()为 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