Le premier index est défini sur null (vide), mais il n'imprime pas la bonne sortie, pourquoi?Pourquoi list.get (0) .equals (null) ne fonctionne-t-il pas?
//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
}
}
Une astuce: 'System.out.println (Arrays.asList (null," High "," High "," High "," High "," High "));' fait ce que vous voulez sans tout cela code supplémentaire. Je dis que c'est le "même" parce que vous ne saviez probablement pas que vous pouviez imprimer des nulls – Pyrolistical