Collection接口、List接口及迭代器
来源:互联网 发布:js手机端上传图片 编辑:程序博客网 时间:2024/06/08 14:37
在java类库中,集合的概念在Collection接口中得到抽象。
Collection接口中的一些方法
public interface MyCollection<T> extends MyIterator<T>{int size();boolean isEmpty();void clear();boolean contains(T element);boolean add(T element);boolean remove(T element);MyIterator<T> myIterator();}
在Collection接口中有一个获取迭代器的方法,用于获取迭代器,迭代器中的方法有
public interface MyIterator<T> {boolean hasNext();T next();void remove();}在这里我们看到在MyCollection接口和MyIterator接口中都有remove方法,他们的主要区别在于
1、Collection的remove方法必须首先找出要被删除的项,如果知道所要删除的项的准确位置,则使用Collection中的remove方法删除开销较小。而迭代器的remove方法是删除由next方法最新返回的项。
2、在使用Iterator(而不是通过增强for循环间接使用)时:如果对正在被迭代的集合进行结构上的改变(即对集合进行add,remove或clear方法)时,那么迭代器就不再合法(抛出ConcurrentModificationException)
List接口实现Collection接口,其主要方法有:
public interface MyList<T> extends MyCollection<T> {T get(int index);T set(int index,T element);void add(int index,T element);void remove(int index,T element);MyListIterator<T> myListIterator();}
其中有获取迭代器的方法,其迭代器中所含有的方法有:
public interface MyListIterator<T> extends MyIterator<T>{boolean hasPrevious();T previous();void add(T element);void set(T element);}
0 0
- Collection接口、List接口及迭代器
- Collection 接口 & List 接口
- 接口Collection和List
- 慕课网3.2 Collection接口 List 接口 Set接口 Map接口
- Java:Collection.List接口实现
- Collection下的List接口
- Collection接口之List子接口详解
- java中Collection接口&List接口
- Collection接口/List接口/Set接口知识点详解
- 集合Collection接口下Set接口List接口
- 集合及Collection接口简介
- Collection接口和迭代器
- Map、Collection、List接口的总结
- Collection和List接口的remove方法
- Collection子接口(List/Set/Queue/SortedSet)
- Java基础-集合Collection&List接口
- java第十四节-Collection接口-List
- Java之Collection接口之List
- iOS UIView的方法及执行顺序
- 下拉列表+选择+实现网页链接
- Quartz集成Spring的2个方法
- jar、ear、war包
- linux登录MySQL,报错ERROR 1045 (28000)解决办法
- Collection接口、List接口及迭代器
- SVN服务器搭建和使用教程
- Tinker 接入指南
- XML——Schema约束
- 【圈子】提升支付宝芝麻信用评分
- IBM Streams时间序列数据分析
- C语言加密输入法二:使用SHA1加密
- 十分钟搞定pandas
- jquery实现iframe方式的dialog窗口,加关闭并刷新父窗口功能