Java中检查Null、空或仅为空白字符串。
我们可以使用String 类的 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