每天学点Java知识 ------> 允许重复的子接口List
上一篇 /
下一篇 2014-07-28 13:54:53
/ 个人分类:Java学习
List是Collection的一个最为常用的子接口,定义方式:
public interface List<E> extends Collection<E>
List接口直接继承了Collection接口,但是List接口对Collection接口进行了大量的扩充,主要方法如:
1.public E get(int index)
取得指定索引位置上的数据
2.public E set(int index, E element)
修改指定索引位置上的数据
3.public ListIterator<E> listIterator()
为ListIterator接口实例化
以上3个方法只是针对List接口起作用,List接口有两个常用的子类:ArrayList和Vector
新的子类:ArrayList
ArrayList是List子接口中使用最多的一个子类
public class TestJava{
public static void main(String args[]){
List<String> test = new ArrayList<String>();
test.add("hello");
test.add("hello");
test.add("world");
for(int x=0; x<test.size(); x++){
String str = test.get(x);
System.out.println(str + ",");
}
}
}
程序运行结果:
hello,
hello,
world,
List集合即能存在重复数据,也可以正常保存,而且数据保存的顺序就是存入数据的顺序
收藏
举报
TAG: