Java String isEmpty() 方法

定义和用法

isEmpty() 方法检查字符串是否为空。

如果字符串为空(length() 为 0),则此方法返回 true,否则返回 false

实例

判断字符串是否为空:

String myStr1 = "Hello";
String myStr2 = "";
System.out.println(myStr1.isEmpty());
System.out.println(myStr2.isEmpty());

亲自试一试

语法

public boolean isEmpty()

参数

无参数。

技术细节

返回:

boolean 值:

  • true - 字符串为空(length() 为 0)
  • false - 字符串不为空