Java中的String类提供了一个isEmpty()方法,用于判断字符串是否为空
下面通过具体的例子来说明
@Test
public void testMethod1() {
String str = new String();
Assert.assertEquals(true, str.isEmpty()); //通过测试
}
@Test
public void testMethod2() {
String str = "";
Assert.assertEquals(true, str.isEmpty()); //通过测试
}
总结:当str.length()返回0时,String类的isEmpty()将返回true