第一个索引设置为 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
}
}
最佳答案
我相信你想做的是改变,
if(choice.get(0).equals(null))
到
if(choice.get(0) == null))
关于java - 为什么 list.get(0).equals(null) 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2556978/