Tag

ArrayList.subList

1 views collected around this technical thread.

Architect's Guide
Architect's Guide
Jun 2, 2024 · Fundamentals

Pitfalls and Best Practices of Arrays.asList and ArrayList.subList in Java

This article explains how Java's Arrays.asList creates a fixed‑size list that throws UnsupportedOperationException on add/remove, and how ArrayList.subList returns a mutable view whose non‑structural changes affect both the original list and the sublist while structural changes can trigger ConcurrentModificationException, providing code examples and practical guidelines.

ArrayList.subListArrays.asListCollections
0 likes · 9 min read
Pitfalls and Best Practices of Arrays.asList and ArrayList.subList in Java
Top Architect
Top Architect
Mar 29, 2021 · Fundamentals

Pitfalls of Using Arrays.asList and ArrayList.subList in Java

This article explains common traps when using Java's Arrays.asList and ArrayList.subList methods, including why add operations throw UnsupportedOperationException, how subList creates a view that shares modifications with the original list, and the circumstances that lead to ConcurrentModificationException.

ArrayList.subListArrays.asListCollections
0 likes · 8 min read
Pitfalls of Using Arrays.asList and ArrayList.subList in Java
Java Captain
Java Captain
Mar 27, 2021 · Fundamentals

Pitfalls of Using Arrays.asList and ArrayList.subList in Java

This article explains common pitfalls when using Java's Arrays.asList and ArrayList.subList methods, illustrating why add operations cause UnsupportedOperationException, how subList creates a view that shares modifications with the original list, and provides best‑practice recommendations to avoid runtime errors.

ArrayList.subListArrays.asListCollections
0 likes · 8 min read
Pitfalls of Using Arrays.asList and ArrayList.subList in Java