标签:包含 highlight new pre object 指定 style main string
/*
* Collection是集合的顶层接口,它的子体系有重复的,有唯一的,有有序的,有无序的
*
* Collection的功能概述
* 1添加功能
* boolean add(Object obj);添加一个元素
* boolean addAll(Collection c);添加一个集合的元素
*
* 2删除元素
* void clear();移除所有元素
* boolean remove(Object o);移除一个元素
* boolean removeAll(Collection c);移除一个集合的元素(是一个还是所有?是所有)
*
* 3判断功能
* boolean contains(Object o);判断集合中是否包含指定的元素
* boolean containsAll(Collection c);判断集合中是否包含指定的集合元素(是一个还是所有,是一个)
* boolean isEmpty();判断集合是否为空
*
* 4获取功能
* Iterator<E> iterator()
*
* 5长度功能
* int size();元素的个数
*
* 6交集功能
* boolean retainAll(Collection c);
*
* 7把集合转换为数组
* Object[] toArray();
* */
import java.util.ArrayList;
import java.util.Collection;
/*
* Collection是集合的顶层接口,它的子体系有重复的,有唯一的,有有序的,有无序的
*
* Collection的功能概述
* 1添加功能
* boolean add(Object obj);添加一个元素
* boolean addAll(Collection c);添加一个集合的元素
*
* 2删除元素
* void clear();移除所有元素
* boolean remove(Object o);移除一个元素
* boolean removeAll(Collection c);移除一个集合的元素(是一个还是所有?是所有)
*
* 3判断功能
* boolean contains(Object o);判断集合中是否包含指定的元素
* boolean containsAll(Collection c);判断集合中是否包含指定的集合元素(是一个还是所有,是一个)
* boolean isEmpty();判断集合是否为空
*
* 4获取功能
* Iterator<E> iterator()
*
* 5长度功能
* int size();元素的个数
*
* 6交集功能
* boolean retainAll(Collection c);
*
* 7把集合转换为数组
* Object[] toArray();
* */
public class IntegerDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
Collection c1 = new ArrayList();
Collection c2 = new ArrayList();
c1.add("hello1");
c1.add("hello2");
c1.add("hello3");
c1.add("hello4");
c2.add("hello4");
c2.add("hello5");
c2.add("hello6");
System.out.println("c1:" + c1);
System.out.println("c2:" + c2);
c1.addAll(c2);// 元素可以重复
System.out.println("c1:" + c1);
System.out.println("c2:" + c2);
// c1.removeAll(c2);//移除元素,重复的元素也会全部移除
System.out.println("c1:" + c1);
System.out.println("c2:" + c2);
System.out.println(c1.containsAll(c2));// 只有包含所有的元素,才叫做包含
System.out.println(c1.retainAll(c2));// 如果有交集,返回true,否则返回false
System.out.println("c1:" + c1);
System.out.println("c2:" + c2);
}
}
2156156
标签:包含 highlight new pre object 指定 style main string
原文地址:http://www.cnblogs.com/denggelin/p/6286520.html