mardi 11 juillet 2017

Order of operations in if statement

I have the following if structure

ArrayList<String> list;
if(list != null){
      if(list.get(0).equals("value"){
            //do stuff
      }
}

is it possible to write this as one if statement? (the second if statement would make no sense if the first if statement results in false, because it would throw NullPointerException)

Aucun commentaire:

Enregistrer un commentaire