日期:2014-05-20  浏览次数:20788 次

简单问题,要线等
package   com;

import   java.util.*;
public   class   CollectionOp2   {
private   static   String   str[]={ "one ", "two ", "three ", "four ", "five "};

/**
  *   @param   args
  */
public   static   void   main(String[]   args)   {
//   TODO   Auto-generated   method   stub
Collection   c=new   ArrayList();//ArrayList   c=new   ArrayList;?
for(int   i=0;i <str.length;i++)
if(c.add(str[i]))
System.out.println( "adding\ " "+str[i]+ "\ " ");
if(c.remove(str[0]))
System.out.println( "removing\ " "+str[0]+ "\ " ");
System.out.println( "Collection: "+c);
System.out.println( "Collection 's   size: "+c.size());
System.out.println( "Is   Collection   empty? "+c.isEmpty());
System.out.println( "Dose   collection   contain "+str[0]+ "? "+c.contains(str[0]));
System.out.println( "Dose   collection   contain "+str[1]+ "? "+c.contains(str[1]));


}

}


Collection   c=new   ArrayList();
ArrayList   c=new   ArrayList;
我想问的问题就是上面的两行有什么区别?在书本这样定义的Collection   c=new   ArrayList();
但我可以像这样定义ArrayList   c=new   ArrayList;

Collection     ArrayList   這兩個都是类吗?
ArrayList     是Collection子类吗?
高手请教,谢谢。


------解决方案--------------------
Collection是层次结构中的根接口,而ArrayList是一个已实现Collection的类