Collection集合的增删改查
public class CollectionTest {
public static void main(String[] args) {
Collection c1 = new ArrayList();
System.out.println("c1 = " + c1);
System.out.println("----------------------------");
boolean b1 = c1.add(new String("one"));
System.out.println("b1 = " + b1);
System.out.println("c1 = " + c1);
b1 = c1.add(new Integer(2));
System.out.println("b1 = " + b1);
System.out.println("c1 = " + c1);
b1 = c1.add(new Student(1001, "zhangfei", 30));
System.out.println("b1 = " + b1);
System.out.println("c1 = " + c1);
System.out.println("----------------------------");
boolean b2 = c1.contains(new String("one"));
System.out.println("b2 = " + b2);
b2 = c1.contains(new String("two"));
System.out.println("b2 = " + b2);
b2 = c1.contains(new Student(1001, "zhangfei", 30));
System.out.println("b2 = " + b2);
System.out.println("----------------------------");
System.out.println("c1 = " + c1);
boolean b3 = c1.remove(new Integer(1));
System.out.println("b3 = " + b3);
System.out.println("c1 = " + c1);
b3 = c1.remove(new Integer(2));
System.out.println("b3 = " + b3);
System.out.println("c1 = " + c1);
c1.clear();
System.out.println("c1 = " + c1);
System.out.println("----------------------------");
System.out.println("集合中元素的个数有:" + c1.size());
System.out.println(0 == c1.size()? "集合已经空了": "集合还没有空");
System.out.println(c1.isEmpty()? "集合已经空了": "集合还没有空");
}
}