Tag

ArrayList

1 views collected around this technical thread.

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.asListJava
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.asListJava
0 likes · 9 min read
Why Arrays.asList() Can Crash Your Java App and How to Fix It
IT Services Circle
IT Services Circle
Jan 10, 2024 · Backend Development

Why Using forEach to Remove Elements from an ArrayList Throws ConcurrentModificationException and How to Delete Safely

The article explains why iterating an ArrayList with forEach and removing elements causes a ConcurrentModificationException, analyzes the underlying fail‑fast iterator behavior, and presents three correct ways—using Iterator.remove, removeIf, and collecting then removing—to delete elements safely.

ArrayListConcurrentModificationExceptionIterator
0 likes · 4 min read
Why Using forEach to Remove Elements from an ArrayList Throws ConcurrentModificationException and How to Delete Safely
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
Oct 18, 2022 · Fundamentals

Common Pitfalls When Using Java List Implementations and How to Avoid Them

This article systematically examines ten typical pitfalls encountered when converting arrays to lists, performing add/remove operations, using subList, handling memory consumption, and working with thread‑safe collections such as CopyOnWriteArrayList in Java, and provides concrete code‑level solutions and performance recommendations.

ArrayListJavaLinkedList
0 likes · 20 min read
Common Pitfalls When Using Java List Implementations and How to Avoid Them
Wukong Talks Architecture
Wukong Talks Architecture
Oct 18, 2021 · Fundamentals

Understanding Thread Safety Issues in Java Collections: ArrayList, HashSet, and HashMap

This article explains the thread‑unsafe nature of Java’s ArrayList, HashSet and HashMap, details their internal implementations and growth mechanisms, and presents three common solutions—Vector, synchronized wrappers, and CopyOnWrite collections—to achieve thread safety in concurrent environments.

ArrayListJavaThread Safety
0 likes · 15 min read
Understanding Thread Safety Issues in Java Collections: ArrayList, HashSet, and HashMap
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Sep 25, 2021 · Fundamentals

Overview of Java Collection Framework and Core Concepts

This article provides a comprehensive overview of Java collections, covering the definition, characteristics, differences from arrays, advantages, common collection classes, underlying data structures, fail‑fast mechanism, detailed List, Set, Queue, and Map interfaces, as well as HashMap and ConcurrentHashMap implementations and best practices.

ArrayListData StructuresHashMap
0 likes · 30 min read
Overview of Java Collection Framework and Core Concepts
Java Tech Enthusiast
Java Tech Enthusiast
Aug 29, 2021 · Fundamentals

Java ArrayList: Constructors, add/addAll, set/get, and Iterator Mechanics

Java’s ArrayList offers a no‑arg constructor initializing an empty internal array, lazy default capacity of ten, and overloads for initial capacity or collection copying; its add/addAll methods ensure and grow capacity, set/get access elements, and its iterator tracks modCount to detect concurrent modifications.

ArrayListDataStructureIterator
0 likes · 16 min read
Java ArrayList: Constructors, add/addAll, set/get, and Iterator Mechanics
Selected Java Interview Questions
Selected Java Interview Questions
Jun 4, 2021 · Fundamentals

Why Removing Elements During forEach on an ArrayList Triggers ConcurrentModificationException and How to Fix It

The article explains that deleting elements from an ArrayList inside a forEach loop can cause a ConcurrentModificationException because the iterator's expected modification count diverges from the actual count, and it shows correct ways to remove items safely using an explicit Iterator or a CopyOnWriteArrayList.

ArrayListConcurrentModificationExceptionIterator
0 likes · 5 min read
Why Removing Elements During forEach on an ArrayList Triggers ConcurrentModificationException and How to Fix It
Architecture Digest
Architecture Digest
Apr 16, 2021 · Backend Development

Five Methods to Remove Duplicates from a Java ArrayList

This article presents five distinct techniques for eliminating duplicate elements from a Java ArrayList, including using LinkedHashSet, Java 8 Stream distinct, HashSet with order preservation, manual contains checks, and a double‑for‑loop approach, each accompanied by complete code examples and output results.

ArrayListDuplicate RemovalHashSet
0 likes · 6 min read
Five Methods to Remove Duplicates from a Java ArrayList
Top Architect
Top Architect
Feb 10, 2021 · Backend Development

Understanding Thread Safety Issues in Java ArrayList and How to Fix Them

This article explains why Java's ArrayList is not thread‑safe, illustrates the two main concurrency problems—array index out‑of‑bounds and element overwriting—through source‑code analysis and multithreaded examples, and presents several practical solutions such as synchronized wrappers, explicit locking, CopyOnWriteArrayList and ThreadLocal.

ArrayListJavaThread Safety
0 likes · 11 min read
Understanding Thread Safety Issues in Java ArrayList and How to Fix Them
Top Architect
Top Architect
Jan 29, 2021 · Fundamentals

Five Ways to Remove Duplicates from a Java ArrayList

This article presents five distinct methods for eliminating duplicate elements from a Java ArrayList, including using LinkedHashSet, Java 8 streams, HashSet with order preservation, manual iteration with contains checks, and nested loops, each accompanied by complete code examples and output results.

ArrayListDuplicate RemovalHashSet
0 likes · 6 min read
Five Ways to Remove Duplicates from a Java ArrayList
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.

ArrayListArrays.asListCollections.addAll
0 likes · 8 min read
Comparing Three Ways to Convert Java Arrays to List and Their Use Cases
Wukong Talks Architecture
Wukong Talks Architecture
Aug 31, 2020 · Fundamentals

Understanding Thread Safety Issues in Java Collections: ArrayList, HashSet, HashMap and Their Solutions

This article explains why core Java collection classes such as ArrayList, HashSet, and HashMap are not thread‑safe, demonstrates the underlying mechanisms of their initialization and resizing, and presents multiple approaches—including Vector, synchronized wrappers, and CopyOnWrite variants—to achieve safe concurrent access.

ArrayListHashMapHashSet
0 likes · 16 min read
Understanding Thread Safety Issues in Java Collections: ArrayList, HashSet, HashMap and Their Solutions
Selected Java Interview Questions
Selected Java Interview Questions
Aug 18, 2020 · Backend Development

ArrayList vs LinkedList in Java: Implementation, Performance, and Usage

This article explains the internal workings of Java's ArrayList and LinkedList, covering their dynamic array and linked list structures, growth mechanisms, performance characteristics for random access, insertion, and deletion, and includes source code excerpts and visual diagrams to illustrate key differences.

ArrayListData StructuresJava
0 likes · 4 min read
ArrayList vs LinkedList in Java: Implementation, Performance, and Usage
Full-Stack Internet Architecture
Full-Stack Internet Architecture
Jul 26, 2020 · Backend Development

Common Java Collection Framework Interview Questions and Answers

This article reviews the most frequently asked Java collection framework interview questions, covering differences between ArrayList, LinkedList, Vector, ArrayDeque, HashSet, HashMap, Hashtable, and the distinction between Collection and Collections, while explaining underlying implementations and performance considerations.

ArrayListHashMapInterview
0 likes · 11 min read
Common Java Collection Framework Interview Questions and Answers
Selected Java Interview Questions
Selected Java Interview Questions
Jul 17, 2020 · Fundamentals

Deep Dive into Java ArrayList: Implementation, Thread Safety, and Common Operations

This article provides an in‑depth explanation of Java's ArrayList, covering its purpose, lack of thread safety, detailed source‑code analysis of fields, constructors and core methods, serialization mechanics, capacity handling, and a simplified hand‑written implementation for interview preparation.

ArrayListCodingInterviewDataStructure
0 likes · 13 min read
Deep Dive into Java ArrayList: Implementation, Thread Safety, and Common Operations
Java Captain
Java Captain
Jun 10, 2020 · Fundamentals

Understanding java.util.ConcurrentModificationException and Safe Ways to Remove Elements from a List

This article explains why using a foreach loop to remove elements from a Java List triggers java.util.ConcurrentModificationException, analyzes the underlying iterator mechanism, and presents three safe alternatives: iterator.remove(), forward-index loop with index adjustment, and reverse-index loop.

ArrayListCollectionConcurrentModificationException
0 likes · 6 min read
Understanding java.util.ConcurrentModificationException and Safe Ways to Remove Elements from a List
Architect's Tech Stack
Architect's Tech Stack
Jun 7, 2020 · Backend Development

How to Avoid java.util.ConcurrentModificationException When Removing Elements from a List

This article explains why a foreach loop over an ArrayList can throw java.util.ConcurrentModificationException when removing elements, analyzes the underlying iterator mechanism, and presents three safe alternatives—using Iterator.remove(), a forward-index for loop with index correction, and a reverse for loop—to modify collections without errors.

ArrayListConcurrentModificationExceptionIterator
0 likes · 7 min read
How to Avoid java.util.ConcurrentModificationException When Removing Elements from a List