在Java中,可以使用以下方法来判断一个字符串是否为空:
使用isEmpty()方法:String str = "";if (str.isEmpty()) { System.out.println("字符串为空");} else { System.out.println("字符串不为空");}使用length()方法:String str = "";if (str.length() == 0) { System.out.println("字符串为空");} else { System.out.println("字符串不为空");}使用equals()方法:String str = "";if (str.equals("")) { System.out.println("字符串为空");} else { System.out.println("字符串不为空");}这些方法都可以用来判断一个字符串是否为空,可以根据实际需求选择其中的一种方法来使用。


