【发布时间】:2010-03-31 22:39:54
【问题描述】:
第一个索引设置为null(空),但它没有打印正确的输出,为什么?
//set the first index as null and the rest as "High"
String a []= {null,"High","High","High","High","High"};
//add array to arraylist
ArrayList<Object> choice = new ArrayList<Object>(Arrays.asList(a));
for(int i=0; i<choice.size(); i++){
if(i==0){
if(choice.get(0).equals(null))
System.out.println("I am empty"); //it doesn't print this output
}
}
【问题讨论】:
-
小窍门:
System.out.println(Arrays.asList(null,"High","High","High","High","High"));无需所有额外代码即可满足您的需求。我说它是“相同的”,因为你可能不知道你可以打印空值