java - Best way to only test for a condition if another condition is false -
so i've got function uses arraylist, , want this:
if(/*1*/ thearraylist.size() == 0 || /*2*/ thearraylist.get(somenumber).someboolean){....
the problem function can triggered @ time when arraylist empty, cause error in sec half of if statement. changed this:
if(thearraylist.size() == 0){ //do code } else if(thearraylist.get(somenumber).someboolean){ //do same code above } else...
but sense obtuse , there must easier way. how can create test sec half of if statement if first half has been proven false?
this not cause error on sec half of if statement. you're using || short-circuit or. means if first part true (the array list empty) sec part not evaluated.
java if-statement arraylist
No comments:
Post a Comment