Add element during arrayList iteraction

I want to add some elements to an arrayList during iteraction, but I want to add in the final of the list, I have tried with ListIterator but only adds after the actual element on interaction…

Example:

ArrayList<Integer> arr = new ArrayList<>(Arrays.asList(new Integer[]{1,2,3,4,5}));      
for (ListIterator<Integer> i = arr.listIterator(); i.hasNext();) {          
    i.add(i.next() + 10);               
}       
System.out.println(arr);

That prints: [1, 11, 2, 12, 3, 13, 4, 14, 5, 15]

What I have to do to get: [1, 2, 3, 4, 5, 11, 12, 13, 14, 15] ?

Thanks


Source: New Questions

Leave a Reply