Title: Java ArrayList — 38 Resizes, 225M Copies, Monday OOMs
Open Graph Title: Java ArrayList — 38 Resizes, 225M Copies, Monday OOMs
Description: A 15M-row ArrayList without initialCapacity triggered 38 resizes and heap fragmentation. One capacity hint eliminated weekly OutOfMemoryError crashes.
Open Graph Description: A 15M-row ArrayList without initialCapacity triggered 38 resizes and heap fragmentation. One capacity hint eliminated weekly OutOfMemoryError crashes.
Opengraph URL: https://thecodeforge.io/java/arraylist-java/
Domain: thecodeforge.io
{
"@context": "https://schema.org",
"@type": "TechArticle",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://thecodeforge.io/java/arraylist-java/"
},
"headline": "Java ArrayList — 38 Resizes, 225M Copies, Monday OOMs",
"description": "A 15M-row ArrayList without initialCapacity triggered 38 resizes and heap fragmentation. One capacity hint eliminated weekly OutOfMemoryError crashes.",
"keywords": "Java ArrayList — 38 Resizes, 225M Copies, Monday OOMs, Java, Intermediate, Collections, A 15M-row ArrayList without initialCapacity triggered 38 resizes and heap fragmentation. One capacity hint eliminated weekly OutOfMemoryError crashes.",
"proficiencyLevel": "Intermediate",
"author": {
"@type": "Person",
"@id": "https://thecodeforge.io/about/#naren",
"name": "Naren",
"url": "https://thecodeforge.io/about/"
},
"publisher": {
"@type": "Organization",
"@id": "https://thecodeforge.io/#org",
"name": "TheCodeForge",
"url": "https://thecodeforge.io",
"logo": {"@type": "ImageObject", "url": "https://thecodeforge.io/assets/og-image.png"}
},
"datePublished": "2026-03-05T00:00:00+00:00",
"dateModified": "2026-08-30T00:00:00+00:00",
"url": "https://thecodeforge.io/java/arraylist-java/",
"inLanguage": "en",
"educationalLevel": "Intermediate",
"image": "https://thecodeforge.io/assets/og-image.png",
"isPartOf": {"@id": "https://thecodeforge.io/#website"}
}
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{"@type": "ListItem", "position": 1, "name": "Home", "item": "https://thecodeforge.io/"},
{"@type": "ListItem", "position": 2, "name": "Java", "item": "https://thecodeforge.io/java/"},
{"@type": "ListItem", "position": 3, "name": "Java ArrayList — 38 Resizes, 225M Copies, Monday OOMs", "item": "https://thecodeforge.io/java/arraylist-java/"}
]
}
{
"@context": "https://schema.org",
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "What is the default initial capacity of an ArrayList?",
"acceptedAnswer": {
"@type": "Answer",
"text": "The default initial capacity is 10. When you create `new ArrayList<>()` without specifying a capacity, Java allocates an internal Object[] array of size 10."
}
},
{
"@type": "Question",
"name": "How does ArrayList resize internally?",
"acceptedAnswer": {
"@type": "Answer",
"text": "When the backing array is full, ArrayList allocates a new array that is approximately 50% larger (e.g., 10 → 15, 15 → 22) and copies all existing elements using System.arraycopy(). This is an O(n) operation."
}
},
{
"@type": "Question",
"name": "Why does removing elements during iteration cause ConcurrentModificationException?",
"acceptedAnswer": {
"@type": "Answer",
"text": "ArrayList maintains a structural modification count. When you remove an element directly via the list (e.g., `list.remove(i)`) while iterating with an enhanced for-loop or iterator, the count changes unexpectedly, triggering the exception. Use `Iterator.remove()` or `removeIf()` instead."
}
},
{
"@type": "Question",
"name": "When should I use LinkedList instead of ArrayList?",
"acceptedAnswer": {
"@type": "Answer",
"text": "Use LinkedList when you need frequent insertions or deletions at the head or tail (queue/stack operations) and don't need random access. For most other workloads, ArrayList's O(1) positional access and better cache locality outperform LinkedList's O(n) positional access and pointer overhead."
}
}
]
}
| og:type | website |
| og:image | https://thecodeforge.io/assets/og-image.png |
| og:image:width | 1200 |
| og:image:height | 630 |
Links:
Viewport: width=device-width, initial-scale=1.0
Robots: max-image-preview:large