Java判断String是否为空或不为空(而且equals的好的写法,不报空指针)

首先澄清一个概念:markdown String str; if(str == null || str.equals(" ")){ } 1 2 3   str == null 说明str还未指向一个特定的字符串对象,此时谈不上是否为空。str = “”;说明str是个空字符串,只不过长度为0;测试 字符串判断空的几种写法:this //①.最多人使用的一个方法, 直观, 方便, 但效率很低;
相关文章
相关标签/搜索