1,Iterable转List
Iterable<Entity> geted = entityDao.findAll();
List<Entity> list = Lists.newArrays();
geted.forEach(single ->{list.add(single)});
学习了:https://blog.csdn.net/u010003051/article/details/53422741
Iterator转List
方式1:
#Apache Commons Collections:
import org.apache.commons.collections.IteratorUtils;
Iterator<Element> myIterator = //some iterator
List<Element> myList=IteratorUtils.toList(myIterator);
方式二:
或者自己转换
public static <T> List<T> copyIterator(Iterator<T> iter) {
List<T> copy = new ArrayList<T>();
while (iter.hasNext())
copy.add(iter.next());
return copy;
}
使用方式:
List<String> list = Arrays.asList("1", "2", "3");
Iterator<String> iter = list.iterator();
Lis