if('\0' == b){
System.out.println("b為空字符");
}else{
System.out.println("判斷不為空");
}
String str = String.valueOf(b);
if ("\0".equals(str)) {
System.out.println("為空");
} else {
System.out.println("不為空" + str);
}
if (str.length() == 1) {
System.out.println("為空");
} else {
System.out.println("不為空" + str);
}
注:String類型的空格哪怕用 char[] haveNull = str.toCharArray();轉換,char數組是變成了空格的字符進行存儲,而非'\0'的形式!