src/share/classes/java/util/LinkedList.java

Print this page

        

@@ -952,14 +952,14 @@
 
         public void forEachRemaining(Consumer<? super E> action) {
             Objects.requireNonNull(action);
             while (modCount == expectedModCount && nextIndex < size) {
                 action.accept(next.item);
+                lastReturned = next;
                 next = next.next;
                 nextIndex++;
             }
-            lastReturned = next;
             checkForComodification();
         }
 
         final void checkForComodification() {
             if (modCount != expectedModCount)