Collection中常用的方法

2019-05-15  本文已影响0人  御都

【1 Collection的功能】存放的元素都是对象

package it.cast01;

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

public class CollectionDemo5 {
    public static void main(String[] args) {
        Collection c = new ArrayList();
        c.add("hello");
        c.add("world");
        Collection c2 = new ArrayList();
        c2.add("hello");
        c2.add("world");
        c2.add("java");
        Collection c3 = new ArrayList();
        c3.add("home");
        
        System.out.println(c.retainAll(c2));
        System.out.println("c = "+c);
        System.out.println(c.retainAll(c3));
        System.out.println("c = "+c);
    }
}

运行结果为:

false
c = [hello, world]
true
c = []
上一篇 下一篇

猜你喜欢

热点阅读