Collection类的子类List

来源:互联网 发布:开发者没有网络adb调试 编辑:程序博客网 时间:2024/04/24 01:26
*单值保存的最大父接口Collection
如下是Collection接口的全部方法
boolean add(E e) //向集合之中保存数据
boolean addAll(Collection<? extends E> c)//将指定集合中的全部元素添加到该集合中
void clear() //清空集合
boolean contains(Object o) //查询集合之中是否有指定的元素
boolean containsAll(Collection<?> c) //判断该集合中是否包含指定集合的全部元素
boolean isEmpty() //判断集合是否为空
Iterator<E> iterator() //为Iterator接口实例化
boolean remove(Object o) //删除对象需要equals
boolean removeAll(Collection<?> c) //删除指定集合中的全部元素
int size() //取得集合的长度
Object[] toArray() //将集合以数组的形式返回
最常用的add();和Iterator(),以上方法很多都用不到(已经过时了),最常用的而是Collection的子类List类和set类
*Colection类的子类List类
get(int index) ;//取得指定位置索引上的对象
set(int index, E element//修改指定位置索引上的对象
public ListIterator<e>ListIterator();//为ListIterator接口实例化
在完成接口后如果想使用接口那么一定需要子类,那么最常用的两个类ArrayList和Vector类
*List类的新子类ArrayList
范例
List<String>all=new ArrayList<String>();
System.out.println(all.add("Hello Word!"));
*List类的旧的子类Vector
既然vector也是List的子类所以在使用上不会有任何的区别。但是ArrayList采用的是异步处理所以性能较高,而Vector使用的是同步处理性能较差,但是ArrayList的安全性较差,而Vector的安全性能较高。但是在往后的开发过程中大多都是采用异步处理,所以使用ArrayList居多。


0 0