Tagged articles
27 articles
Page 1 of 1
Coder Trainee
Coder Trainee
Mar 3, 2026 · Fundamentals

Common Pitfalls When Using Java List Collections

The article explains three typical traps when working with Java List: Arrays.asList returns a fixed‑size list that throws UnsupportedOperationException on add/remove, iterating and removing elements directly also fails, and converting primitive arrays with Arrays.asList produces an unexpected single‑element list.

Arrays.asListCollectionsJava
0 likes · 4 min read
Common Pitfalls When Using Java List Collections
Java Backend Technology
Java Backend Technology
Jun 14, 2025 · Backend Development

Why Arrays.asList() Can Crash Your Java App and How to Fix It

This article explains why using Java's Arrays.asList() to convert an array into a List can cause UnsupportedOperationException at runtime, illustrates the hidden fixed‑size list implementation, shows the severe impact on an e‑commerce system, and provides a safe solution using java.util.ArrayList to avoid such crashes.

ArrayListArrays.asListCollections
0 likes · 8 min read
Why Arrays.asList() Can Crash Your Java App and How to Fix It
Architect's Guide
Architect's Guide
Mar 26, 2025 · Fundamentals

Avoiding the Fixed‑Size List Pitfall of Arrays.asList in Java

This article explains why using Arrays.asList to convert an array into a List can produce an immutable, fixed‑size list that throws UnsupportedOperationException on add or remove operations, illustrates the issue with real‑world incident details, analyzes the internal implementation, and provides a safe replacement using java.util.ArrayList.

ArrayListArrays.asListCollections
0 likes · 9 min read
Avoiding the Fixed‑Size List Pitfall of Arrays.asList in Java
macrozheng
macrozheng
Feb 10, 2025 · Backend Development

Why Arrays.asList() Can Crash Your Java App and How to Fix It

This article explains how using Arrays.asList() to convert an array into a List creates a fixed‑size collection that throws UnsupportedOperationException on add or remove operations, illustrates the issue with a real e‑commerce incident, and shows how to safely wrap the result with a mutable java.util.ArrayList.

ArrayListArrays.asListBackend Development
0 likes · 9 min read
Why Arrays.asList() Can Crash Your Java App and How to Fix It
IT Services Circle
IT Services Circle
Dec 26, 2024 · Fundamentals

Understanding the JDK Bug in Arrays.asList().toArray() and Its Fix in JDK 9

This article explains a long‑standing JDK bug where Arrays.asList().toArray() returns an Object[] that causes ArrayStoreException when modified, analyzes the underlying implementation differences between java.util.ArrayList and Arrays$ArrayList, and describes how the issue was finally fixed in JDK 9.

ArrayStoreExceptionArrays.asListJDK
0 likes · 9 min read
Understanding the JDK Bug in Arrays.asList().toArray() and Its Fix in JDK 9
DaTaobao Tech
DaTaobao Tech
Aug 23, 2024 · Fundamentals

Common Java Pitfalls and Their Solutions

The article outlines frequent Java pitfalls—including BigDecimal precision loss, immutable lists from Arrays.asList, double division by zero returning Infinity, null values in switch statements, stream filters mutating original objects, and autoboxing nulls causing NullPointerExceptions—and provides clear explanations and practical fixes to enhance code reliability.

Arrays.asListAutoboxingBigDecimal
0 likes · 5 min read
Common Java Pitfalls and Their Solutions
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.

Arrays.asListCollectionsConcurrentModificationException
0 likes · 9 min read
Pitfalls and Best Practices of Arrays.asList and ArrayList.subList in Java
Java Tech Enthusiast
Java Tech Enthusiast
May 1, 2024 · Fundamentals

Pitfalls of Arrays.asList in Java

Java's Arrays.asList method has three major pitfalls: it cannot directly convert primitive arrays like int[] because of autoboxing limits, it returns a fixed-size list that throws UnsupportedOperationException on modification, and the list shares its backing array so changes to the original array are reflected in the list; using Arrays.stream for boxing or wrapping the result in a new ArrayList avoids these issues.

Arrays.asListCode ExamplesCollections
0 likes · 4 min read
Pitfalls of Arrays.asList in Java
Java Tech Enthusiast
Java Tech Enthusiast
Feb 22, 2024 · Backend Development

Common Pitfalls of Arrays.asList in Java

When converting arrays to lists in Java, Arrays.asList cannot handle primitive arrays (treating them as a single element), returns a fixed‑size view that disallows add or remove operations, and shares its backing array so modifications affect both structures, so developers should use boxed streams or copy into a new ArrayList.

Arrays.asListJavaList
0 likes · 4 min read
Common Pitfalls of Arrays.asList in Java
IT Services Circle
IT Services Circle
Feb 19, 2024 · Backend Development

Common Pitfalls When Converting Arrays to Lists with Arrays.asList in Java

This article explains three common pitfalls of using Java's Arrays.asList—its incompatibility with primitive arrays, the immutability of the returned list, and the shared backing array that causes side‑effects—along with practical solutions such as using wrapper types, Streams, or creating a new ArrayList.

Arrays.asListBackend DevelopmentJava
0 likes · 5 min read
Common Pitfalls When Converting Arrays to Lists with Arrays.asList in Java
macrozheng
macrozheng
Nov 2, 2023 · Fundamentals

When to Use List.of vs Arrays.asList in Java: Immutable vs Mutable Lists Explained

This article compares Java's List.of() and Arrays.asList() methods, detailing their immutable versus mutable characteristics, handling of nulls, size constraints, and underlying array behavior, and provides practical code examples and guidance on choosing the appropriate method for different programming scenarios.

Arrays.asListCollectionsImmutable List
0 likes · 7 min read
When to Use List.of vs Arrays.asList in Java: Immutable vs Mutable Lists Explained
Rare Earth Juejin Tech Community
Rare Earth Juejin Tech Community
Oct 20, 2023 · Fundamentals

Understanding Java List.remove Overloads and the Pitfalls of Arrays.asList

This article explains the overloaded remove methods in Java's List interface, demonstrates common mistakes when removing elements from ArrayList, clarifies the behavior of Arrays.asList with primitive arrays versus object arrays, and highlights related issues such as unsupported add/remove operations and index‑based deletions.

ArrayListArrays.asListJava
0 likes · 10 min read
Understanding Java List.remove Overloads and the Pitfalls of Arrays.asList
Java Architect Essentials
Java Architect Essentials
Mar 19, 2023 · Backend Development

Why Arrays.asList and subList Can Throw Unexpected Exceptions in Java

This article explains the hidden pitfalls of Java's Arrays.asList and ArrayList.subList methods, showing how fixed‑size lists cause UnsupportedOperationException, how subList creates a mutable view that can trigger ConcurrentModificationException, and provides concrete code examples and source‑code analysis.

Arrays.asListConcurrentModificationExceptionJava
0 likes · 10 min read
Why Arrays.asList and subList Can Throw Unexpected Exceptions in Java
Java High-Performance Architecture
Java High-Performance Architecture
Oct 17, 2022 · Backend Development

10 Hidden Pitfalls of Java List Implementations and How to Avoid Them

This article examines common traps when using Java List structures such as Arrays.asList, ArrayList, LinkedList, and CopyOnWriteArrayList, explains why they occur, and provides practical solutions—including proper conversion, avoiding unsupported operations, handling subList references, and mitigating memory and concurrency issues.

ArrayListArrays.asListCopyOnWriteArrayList
0 likes · 19 min read
10 Hidden Pitfalls of Java List Implementations and How to Avoid Them
Cognitive Technology Team
Cognitive Technology Team
Aug 6, 2022 · Backend Development

Common Pitfalls of java.util.Arrays.asList in Java

This article explains three major pitfalls when using java.util.Arrays.asList: passing primitive arrays, attempting to modify the returned list, and misunderstanding that the list shares the original array, providing code examples and proper alternatives for each case.

Arrays.asListBackend DevelopmentCollections
0 likes · 6 min read
Common Pitfalls of java.util.Arrays.asList in Java
Programmer DD
Programmer DD
Jan 13, 2022 · Backend Development

Why Arrays.asList and subList Can Throw Unexpected Exceptions in Java

This article explains the hidden pitfalls of Java's Arrays.asList and ArrayList.subList methods, showing why add operations may trigger UnsupportedOperationException and how modifications to original or sub‑lists can cause ConcurrentModificationException, with code examples and visual illustrations.

Arrays.asListCollectionsException
0 likes · 8 min read
Why Arrays.asList and subList Can Throw Unexpected Exceptions in Java
Java Backend Technology
Java Backend Technology
Jun 1, 2021 · Fundamentals

Why Arrays.asList and subList Can Surprise You: Hidden Pitfalls

This article examines common pitfalls when using Java's Arrays.asList and ArrayList.subList methods, explaining why add operations throw UnsupportedOperationException, how subList creates a view that links modifications between original and sublists, and offers best‑practice recommendations to avoid runtime errors.

ArrayListArrays.asListCollections
0 likes · 9 min read
Why Arrays.asList and subList Can Surprise You: Hidden Pitfalls
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.

Arrays.asListConcurrentModificationExceptionUnsupportedOperationException
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.

Arrays.asListConcurrentModificationExceptionJava
0 likes · 8 min read
Pitfalls of Using Arrays.asList and ArrayList.subList in Java
Java Backend Technology
Java Backend Technology
Jan 24, 2021 · Fundamentals

Why Arrays.asList and subList Can Throw Unexpected Exceptions in Java

This article explains common pitfalls when using Java's Arrays.asList and ArrayList.subList methods, illustrating why add operations may trigger UnsupportedOperationException or ConcurrentModificationException, and provides guidance on safe usage to avoid runtime errors in production.

Arrays.asListCollectionsConcurrentModificationException
0 likes · 10 min read
Why Arrays.asList and subList Can Throw Unexpected Exceptions in Java
Java Captain
Java Captain
Nov 2, 2020 · Fundamentals

Comparing Three Ways to Convert Java Arrays to List and Their Use Cases

This article compares three common methods for converting Java arrays to List—Arrays.asList, using an ArrayList constructor, and Collections.addAll—detailing their advantages, limitations, performance, and appropriate scenarios, while also explaining common type conversion errors and best practices for primitive and wrapper types.

ArrayArrayListArrays.asList
0 likes · 8 min read
Comparing Three Ways to Convert Java Arrays to List and Their Use Cases
Big Data Technology & Architecture
Big Data Technology & Architecture
Aug 19, 2019 · Backend Development

Common Pitfalls When Using Arrays.asList in Java

This article explains why using Java's Arrays.asList with primitive arrays can produce unexpected list sizes, why the resulting list is immutable, and provides correct usage patterns with code examples to avoid UnsupportedOperationException and other bugs.

Arrays.asListImmutableJava
0 likes · 6 min read
Common Pitfalls When Using Arrays.asList in Java
Java Captain
Java Captain
Jul 29, 2019 · Backend Development

Why Arrays.asList() Returns an Unmodifiable List in Java

The article explains that Java's Arrays.asList() creates a fixed‑size list backed by the original array, uses an internal ArrayList class without add, remove, or clear methods, and therefore any attempt to modify the list throws UnsupportedOperationException, with work‑arounds shown.

Arrays.asListBackendUnsupportedOperationException
0 likes · 4 min read
Why Arrays.asList() Returns an Unmodifiable List in Java
Java Backend Technology
Java Backend Technology
Jun 10, 2019 · Backend Development

Why Arrays.asList Can Trap You: Common Mistakes and How to Avoid Them

This article explains why using Java's Arrays.asList can lead to unexpected behavior, illustrates three typical pitfalls with primitive arrays, mutable lists, and unsupported modifications, and provides detailed analysis, source code insights, and practical alternatives for safely converting arrays to collections.

Arrays.asListBackend DevelopmentCollections
0 likes · 6 min read
Why Arrays.asList Can Trap You: Common Mistakes and How to Avoid Them