Java集合-Iterable
原文链接 原作者:Jakob Jenkov 译者:祖强
Iterable接口 (java.lang.Iterable) 是Java集合的顶级接口之一。Collection接口继承Iterable,所以Collection的所有子类也实现了Iterable接口。
一个实现Iterable接口的类可以使用新的for循环,下面是一个示例:
[code lang=”java”]
List list = new ArrayList();
for(Object o : list){
//do something o;
}
[/code]
Iterable 接口只有一个方法:
[code lang=”java”]
public interface Iterable<T> {
  public Iterator<T> iterator();
}
[/code]
怎么去实现Iterable接口以便可以使用新的for循环,在我Java泛型教程的这篇文章中Implementing the Iterable Interface可以找到解释。
原创文章,转载请注明: 转载自并发编程网 – ifeve.com本文链接地址: Java集合-Iterable

 (7 votes, average: 4.00 out of 5)
 (7 votes, average: 4.00 out of 5) Loading...
Loading...

暂无评论