加载中...

Collection接口中的方法

  import java.util.*;
  /**
  测试Collection接口中的方法
  */
  public class TestList {
  public static void main(String[] args) {
      Collection<String> c = new ArrayList<>();
      
      System.out.println(c.size());
      System.out.println(c.isEmpty());
      
      c.add("老大");
      c.add("老二");
      System.out.println(c);
  
      c.remove("老二");
      System.out.println(c);  //移除了,但还在
  
      c.clear();  //移除所有元素
  }
}
posted @ 2021-08-14 11:04  nongeason  阅读(36)  评论(0)    收藏  举报