java中的isEmpty()方法做了什么?
java.util.ArrayList 类的 isEmpty() 方法,如果该列表不包含任何元素,则返回 true。
示例
import java.util.ArrayList; public class ArrayListDemo { public static void main(String[] args) { ArrayList<Integer> arrlist = new ArrayList<Integer>(5); arrlist.add(25); arrlist.add(10); arrlist.add(20); arrlist.add(35); boolean retval = arrlist.isEmpty(); if (retval == true) { System.out.println("list is empty"); } else { System.out.println("list is not empty"); } for (Integer number : arrlist) { System.out.println("Number = " + number); } } }
输出
list is not empty Number = 25 Number = 10 Number = 20 Number = 35
广告