成都创新互联网站制作重庆分公司

iterator转list的方法与注意事项

如果使用第三方工具将iterator转为list,有两种方法:
方法1:使用org.apache.commons.collections.IteratorUtils.toList(T)
方法2:使用com.google.common.collect.Lists.newArrayLists(T)

但是不管使用以上哪种方法,都会造成iterator的游标指向最后一行,遍历方法将直接退出。

例子:
Iterator it = new UniqueFilterIterator(li.iterator());
List l = IteratorUtils.toList(it); //方法1
List l = Lists.newArrayList(it); //方法2
while(it.hasNext()){
...
}
在以上代码片段中,不论执行方法1还是方法2,在其后对it执行遍历时,都会直接跳过!
本文名称:iterator转list的方法与注意事项
URL地址:http://cxhlcq.com/article/gieijg.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部