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.

Sign in Create a free account

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