在Java中,可以用isEmpty();判断一个顺序容器ArrayList里面是否有元素,如果有的话返回一个Boolean类型的值false,否则返回true。(Returnstrueif this list contains no elements.) [1]
1
2
3
4
5
6
|
import java.util.ArrayList; //在此处引入ArrayList所在的库 ArrayList<Integer> a = new ArrayList<Integer>(); System.out.println(a.isEmpty()); //打印出true a.add( 5 ); System.out.println(a.isEmpty()); //打印出false |