isEmpty()
public static void main(String[] args){ List<String>list = new ArrayList<String>(); list.add("保护环境"); //向列表中添加数据 list.add("从我做起"); //向列表中添加数据 list.add("爱护地球"); //向列表中添加数据 list.add("从我做起"); //向列表中添加数据 boolean empty = list.isEmpty(); if(empty){ System.out.println("该列表为空"); }else{ System.out.println("该列表不为空"); } list.clear(); //从列表中移除所有元素 System.out.println("执行clear方法后"); empty = list.isEmpty(); if(empty){ System.out.println("该列表为空"); }else{ System.out.println("该列表不为空"); } }运行结果如下:
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有