package com.jasonfeng.dj;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
public class CollectionTest {
public static void main(String[] args) {
Collection<String> cl = new ArrayList<>();
//System.out.println(cl);
cl.add("jason");cl.add("hello");cl.add("jack");cl.add("xm"); //向数组中添加元素
System.out.println(cl);
System.out.println(cl.remove("xm")); //删除数组中其中一个元素
System.out.println(cl);
System.out.println(cl.contains("xm"));
System.out.println("isEmpty"+cl.isEmpty());
System.out.println(cl.size());
Object[] ob = cl.toArray();
System.out.println(Arrays.toString(ob)); //打印数组
for (int i = 0; i < ob.length; i++) { //遍历数组并打印
System.out.println("for"+ob[i]);
}
}
}
Collection几种用法及多态继承
最新推荐文章于 2021-12-28 14:53:58 发布