Weird behaviour of Java iterators -
i've encounter weird problem when using java iterators.
in function receive iterable object called filelist, , perform following :
system.out.println("first iteration:"); for(text t : filelist) system.out.println(t); system.out.println("second iteration:"); for(text t : filelist) system.out.println(t); and output is:
first iteration: file2.txt file1.txt file1.txt second iteration: filelist of type iterable<text>. i'm working hadoop map/reduce framework.
so question is, why file list empty in second loop, when didn't change in first one?
the iterable might return iterator might non-reiterable. nothing in it's interface says can't. in case seems iterable designed library authors used once. if want iterate second time, need store values in own structure. i.e. can first do
list<text> mylist = new arraylist(filelist)
Comments
Post a Comment