Could you explain behaviour of Iterator result:
ArrayList< String > list = new ArrayList< >(
Arrays.asList( new String[] { "a", "b", "c", "d" } ) );
int i = 0;
ListIterator< String > iterator = list.listIterator();
while( iterator.hasNext() ) {
if( ++i == 3 ) {
System.out.println(
iterator.previous() + iterator.nextIndex() );
}
System.out.println( iterator.next() + iterator.nextIndex() );
}
The output is: a1 b2 b1 b2 c3 d4 Why third output is "b1" but not "a1"? I figure the structure
0 1 2 3 element index
a b c d element value
nextIndexis the index that would be returned by callingnext(). Does that answer your question?new String[] { ... }, you can simply useArrays.asList("a", "b", "c", "d").