Files
java-core-examples/sequenced/output/03-reversed-view-is-live-demo.txt

16 lines
664 B
Plaintext

original = [10, 20, 30]
reversedView = [30, 20, 10]
Mutating the ORIGINAL list (original.add(40)):
original = [10, 20, 30, 40]
reversedView = [40, 30, 20, 10] <- updated with no code touching reversedView directly
Mutating the REVERSED VIEW (reversedView.addFirst(0)):
reversedView = [0, 40, 30, 20, 10]
original = [10, 20, 30, 40, 0] <- the 0 landed at the END of the original list
This is a VIEW, confirmed structurally: reversed().reversed() is back to the
same logical order as the original, still backed by the same list:
letters = [x, y, zed]
letters.reversed().reversed() = [x, y, zed] (back to original order, same backing list)