import java.util.*;
public class CollectionDemo {
public static void main(String[] args) {
method_6();
}
public static void method_6(){
Collection col = new ArrayList();
col.add("abc11");
col.add("abc12");
col.add("abc13");
col.add("abc12");
col.add("abc14");
//调用方法toArray 集合转成数组
Object[] arr = col.toArray();
for(int x = 0 ; x < arr.length ; x++){
System.out.println(arr);
}
}
public static void method_5(){
Collection col = new ArrayList();
col.add("abc11");
col.add("abc12");
col.add("abc13");
col.add("abc12");
col.add("abc14");
//获取集合的长度
int size = col.size();
System.out.println(size);
}
public static void method_4(){
Collection col = new ArrayList();
col.add("abc11");
col.add("abc12");
col.add("abc13");
col.add("abc12");
col.add("abc14");
System.out.println("原始集合 "+ col);
//移除集合中的元素 abc12
boolean b = col.remove("abc12");
System.out.println(b);
System.out.println("移除后集合 "+col);
}
public static void method_3(){
Collection col = new ArrayList();
col.add(1);
//判断集合中是不是有元素
boolean b = col.isEmpty();
System.out.println(b);
}
public static void method_2(){
Collection col = new ArrayList();
col.add("abc11");
col.add("abc12");
col.add("abc13");
col.add("abc14");
System.out.println(col);
//判断字符串 abc12 是不是包含在集合中
boolean b = col.contains("abc12");
System.out.println(b);
}
public static void method_1(){
Collection col = new ArrayList();
col.add("abc11");
col.add("abc12");
col.add("abc13");
col.add("abc14");
System.out.println(col);
//清空 clear
System.out.println(col);
}
public static void method(){
//接口指向自己的实现类的对象
Collection col = new ArrayList();
//调用方法add,对称存储到集合
//add方法运行的是 ArrayList实现类重写的
col.add("abc");
col.add(123);
col.add(false); //add (new Boolean (false)) 自动装箱
//输出集合的时候,看到的是集合中存储的元素
//输出方式,目的是为了方便观看,不等于遍历
System.out.println(col);
}
}