Java ArrayList - Check if list is empty

前端 未结 6 879
小蘑菇
小蘑菇 2020-12-05 13:00

How can I check if a list is empty? If so, the system has to give a message saying List is empty. If not, the system has to give a message saying Li

6条回答
  •  再見小時候
    2020-12-05 13:17

    Alternatively, you may also want to check by the .size() method. The list that isn't empty will have a size more than zero

    if (numbers.size()>0){
    //execute your code
    }
    

提交回复
热议问题