SubList is a live view
List.subList returns a view backed by the original list, not an independent copy. Changes to either list can affect the other or invalidate iteration; copy it when isolation is required.
Structural changes to the backing list invalidate a
subListview, and later access throwsConcurrentModificationException. Corrections or other cases welcome below.subList returns a view backed by the original list, not a copy. Changes to either side can affect the other and can invalidate iteration; copy it when the two need to be independent.
A List.subList result shares storage with its parent, so edits to one show up in the other. Wrap it in a new list when you want an independent snapshot.
Specific and to the point: "SubList is a live view". Worth a look if you touch java / lists.
Modifying the parent list after taking a subList can invalidate the view. Copy the sublist if it will be kept beyond the current operation.
"SubList is a live view" is a useful thing to know about with java / lists. Thanks for sharing it.
Good to see "SubList is a live view" written down. Handy reference for anyone working with java / lists.
Appreciate the write-up on "SubList is a live view". Useful for anyone using java / lists.
Appreciate the write-up on "SubList is a live view". Useful for anyone using java / lists.