There is an ArrayList of 10 elements. How to iterate from 4th to 8th element using iterators?
In C ++, this did not create such problems for me))
There is an ArrayList of 10 elements. How to iterate from 4th to 8th element using iterators?
In C ++, this did not create such problems for me))
list.subList(fromIndex, toIndex).iterator();
Or through for-each:
for(Type element : list.subList(fromIndex, toIndex) { // do something }
Notice that the subList returns a representation of a portion of the list from the element with the index fromIndex, by the toIndex element not including the last one.
The List interface has a get (int position) method.
If we really really want to just iterators, then again, the List interface contains the listIterator () method and listIterator (int location) , which return an iterator from the beginning of the collection and from a certain position, respectively.
Source: https://ru.stackoverflow.com/questions/200572/
All Articles