package com.yjf.esupplier.common.test; import java.util.ArrayList; import java.util.Collection; /** * @author shusheng * @description Collection接口成员方法 * @Email shusheng@yiji.com * @date 2018/12/11 16:21 */ public class CollectionDemo1 { public static void main(String[] args) { Collection c = new ArrayList(); ((ArrayList) c).add("hello"); ((ArrayList) c).add("world"); ((ArrayList) c).add("java"); System.out.println("size:"+c.size()); System.out.println("c:" + c); System.out.println("remove:" + c.remove("hello")); System.out.println("remove:" + c.remove("hello")); System.out.println("contains:" + c.contains("world")); System.out.println("contains:" + c.contains("android")); System.out.println("isEmpty:"+c.isEmpty()); c.clear(); System.out.println("isEmpty:"+c.isEmpty()); } }
执行结果:
size:3 c:[hello, world, java] remove:true remove:false contains:true contains:false isEmpty:false isEmpty:true