Der erste Index ist auf Null (leer) gesetzt, aber die richtige Ausgabe wird nicht gedruckt, warum?Warum funktioniert list.get (0) .equals (null) nicht?
//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
}
}
Ein Trick: 'System.out.println (Arrays.asList (Null," Hoch "," Hoch "," Hoch "," Hoch "," Hoch "));' tut, was Sie wollen, ohne all das zusätzlicher Code Ich sage es ist das "selbe", weil Sie wahrscheinlich nicht wussten, dass Sie Nullen drucken können – Pyrolistical