subList is a view, and touching the parent invalidates it

List.subList does not copy. It returns a window onto the original, and any structural change to the parent makes every method on that window throw - which turns a caching or pagination helper into a landmine.

Full code & output

This topic is available to PRO members.

Open this topic Go PRO Sign in Create a free account
More in JAVA

Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.

Published 2026-08-25

© Java Coding Hub · About · Contact · Privacy · Terms