[JAVA] 9.JAVA中的Collection
2021-02-05 18:15
阅读:436
标签:ima item 实现 alt rto 技术 dex lang col
Iterable
这样就可以遍历且不暴露内部成员items
Iterable需要实现Iterator,而Iterator需要实现hasNext和next
import java.util.Iterator;
public class GenericList implements Iterable {
private T[] items = (T[]) new Object[10];
private int count;
public void push(T item) {
items[count++] = item;
}
public T get(int index) {
return items[index];
}
@Override
public Iterator iterator() {
return new ListItertor(this);
}
private class ListItertor implements Iterator {
private GenericList list;
private int index;
public ListItertor(GenericList list) {
this.list = list;
}
@Override
public boolean hasNext() {
return index
其他的实现接口和类
Collection
List Queue Set
ArrayList PriorityQueue HashSet
LinkedList
Hash Table
这个不属于Iterable接口的实现类
[JAVA] 9.JAVA中的Collection
标签:ima item 实现 alt rto 技术 dex lang col
原文地址:https://www.cnblogs.com/modai/p/12786723.html
文章来自:搜素材网的编程语言模块,转载请注明文章出处。
文章标题:[JAVA] 9.JAVA中的Collection
文章链接:http://soscw.com/index.php/essay/51442.html
文章标题:[JAVA] 9.JAVA中的Collection
文章链接:http://soscw.com/index.php/essay/51442.html
评论
亲,登录后才可以留言!