集合

package day35;

import java.util.ArrayList;
import java.util.Collection;

/*
接口 Collection
所有集合的都实现接口;
常用方法
boolean add(E e) 添加元素。
void clear()移除此 collection 中的所有元素
boolean contains(Object o)如果此 collection 包含指定的元素,则返回 true。
boolean isEmpty()判断集合是否为空;
boolean remove(Object o)从此 collection 中移除指定元素的单个实例,如果存在的话(可选操作)。
int size()返回此 collection 中的元素数。
Object[] toArray()返回包含此 collection 中所有元素的数组。
*/
public class list {
public static void main(String[] args) {
ArrayList str=new ArrayList<>();
str.add("胡澳宾");
str.add("李易峰");
str.add("彭于晏");
str.add("王建民");
System.out.println(str);
str.remove("胡澳宾");
System.out.println(str);
System.out.println(str.contains("胡澳宾"));
System.out.println(str.isEmpty());
System.out.println(str.size());
Object []s=str.toArray();
for (int i = 0; i <str.size() ; i++) {
System.out.println(s[i]);
}
str.clear();
System.out.println(str);
}
}
posted @ 2020-10-14 20:42  青竹之下  阅读(110)  评论(0编辑  收藏  举报