{"id":116406,"date":"2026-06-16T20:01:04","date_gmt":"2026-06-16T14:31:04","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=116406"},"modified":"2026-06-16T20:01:06","modified_gmt":"2026-06-16T14:31:06","slug":"what-is-arraylist-in-java","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/what-is-arraylist-in-java\/","title":{"rendered":"What is ArrayList in Java: A Complete Guide"},"content":{"rendered":"\n<p>ArrayList in Java solves the limitation of fixed-size arrays by providing a dynamic list that automatically resizes as needed. It combines the flexibility of dynamic storage with fast array-based access and offers many built-in methods for managing data efficiently.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Quick TL;DR<\/strong><\/h2>\n\n\n\n<ul>\n<li>ArrayList in Java is a dynamic array that automatically resizes as elements are added or removed.&nbsp;<\/li>\n\n\n\n<li>It maintains insertion order, allows duplicates, and provides fast element access, making it one of the most commonly used collection classes in Java.\u00a0<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is ArrayList in Java?<\/strong><\/h2>\n\n\n\n<p>ArrayList in Java is a class in the java.util package that implements the List interface. It stores elements in an internal array and automatically expands its capacity when needed through dynamic resizing, allowing you to add elements without managing array size manually.<\/p>\n\n\n\n<p>Key characteristics of ArrayList in Java:<\/p>\n\n\n\n<ul>\n<li><strong>Dynamic sizing:<\/strong> Grows and shrinks automatically as elements are added or removed<\/li>\n\n\n\n<li>&nbsp;<strong>Ordered:<\/strong> Maintains the insertion order of elements<\/li>\n\n\n\n<li>&nbsp;<strong>Index-based access:<\/strong> Supports O(1) random access by index<\/li>\n\n\n\n<li><strong>Duplicates allowed:<\/strong> Unlike a Set, ArrayList can contain duplicate values<\/li>\n\n\n\n<li>&nbsp;<strong>Null-friendly:<\/strong> Allows null elements<\/li>\n\n\n\n<li><strong>Not thread-safe:<\/strong> Not synchronized by default; use Collections.synchronizedList() or CopyOnWriteArrayList for thread safety<\/li>\n<\/ul>\n\n\n\n<p><strong>Read More: <\/strong><a href=\"https:\/\/www.guvi.in\/blog\/what-is-collection-framework-in-java\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Java Collections Framework Explained<\/strong><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How Does ArrayList in Java Work Internally?<\/strong><\/h2>\n\n\n\n<p>Understanding the internals of ArrayList in Java helps you write more efficient code and make better decisions about when to use it versus other data structures.<\/p>\n\n\n\n<p><em>Check out <a href=\"https:\/\/www.guvi.in\/courses\/programming\/java-programming\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=ArrayList+in+Java%3A+A+Complete+Guide\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>HCL GUVI&#8217;s Java Development Programme<\/strong><\/a> built for students and working professionals who want to build job-ready Java skills with hands-on mentorship.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Initial Capacity<\/strong><\/h3>\n\n\n\n<p>When you create an ArrayList without specifying a size, Java gives it a default initial capacity of 10. This does not mean the list holds 10 elements it means space for 10 elements is pre-allocated internally. You can specify a custom initial capacity if you know roughly how many&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>elements you will store, which avoids unnecessary resizing.<br>\/\/ Default capacity: 10<br>ArrayList&lt;String&gt; list1 = <strong>new<\/strong> ArrayList&lt;&gt;();<br><br>\/\/ Custom initial capacity: 100 (better if you expect ~100 elements)<br>ArrayList&lt;String&gt; list2 = <strong>new<\/strong> ArrayList&lt;&gt;(100);<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Dynamic Resizing<\/strong><\/h3>\n\n\n\n<p>When an ArrayList exceeds its current capacity, it creates a larger internal array (typically 1.5\u00d7 the previous size), copies existing elements, and then adds the new element. Although resizing takes O(n) time, it occurs rarely, so the average (amortized) time complexity of adding elements remains O(1).&nbsp;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Time Complexity of Core Operations<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>Operation<\/strong><\/td><td><strong>Time Complexity<\/strong><\/td><td><strong>Reason<\/strong><\/td><\/tr><tr><td><strong>get(index)<\/strong><\/td><td>O(1)<\/td><td>Direct index-based array access<\/td><\/tr><tr><td><strong>add(element)<\/strong><\/td><td>O(1) amortised<\/td><td>Append at end; rare O(n) resize<\/td><\/tr><tr><td><strong>add(index, element)<\/strong><\/td><td>O(n)<\/td><td>Elements after index must shift right<\/td><\/tr><tr><td><strong>remove(index)<\/strong><\/td><td>O(n)<\/td><td>Elements after index must shift left<\/td><\/tr><tr><td><strong>contains(element)<\/strong><\/td><td>O(n)<\/td><td>Linear search through the array<\/td><\/tr><tr><td><strong>size()<\/strong><\/td><td>O(1)<\/td><td>Size is tracked as a field<\/td><\/tr><tr><td><strong>clear()<\/strong><\/td><td>O(n)<\/td><td>Each element reference is nulled out<\/td><\/tr><tr><td><strong>sort()<\/strong><\/td><td>O(n log n)<\/td><td>Uses TimSort internally<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 800px;\">\n  <strong style=\"font-size: 22px; color: #FFFFFF;\">\ud83d\udca1 Did You Know?<\/strong>\n  <p style=\"margin-top: 14px;\">\n    <strong>ArrayList<\/strong> was introduced in <strong>Java 1.2<\/strong> as part of the <strong>Java Collections Framework<\/strong>, providing a flexible, resizable array implementation for storing elements dynamically. Before its introduction, developers commonly used <strong>Vector<\/strong>, which offers similar functionality but is synchronized by default, making it less efficient in single-threaded environments. Today, <strong>ArrayList<\/strong> is the preferred choice for most non-thread-safe use cases due to its better performance, while thread-safe alternatives such as <strong>CopyOnWriteArrayList<\/strong> or synchronized wrappers like <code>Collections.synchronizedList()<\/code> are used when concurrency control is required. This evolution reflects Java\u2019s shift toward more modular and performance-conscious collection design.\n  <\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Create an ArrayList in Java<\/strong><\/h2>\n\n\n\n<p>There are several ways to create and initialize an ArrayList in Java, depending on your use case.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>import java.util.ArrayList;<\/strong><strong><br><\/strong><strong>import java.util.Arrays;<\/strong><strong><br><\/strong><strong>import java.util.<\/strong><strong>List<\/strong><strong>;<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>\/\/ 1. Empty ArrayList (default capacity 10)<\/strong><strong><br><\/strong><strong>ArrayList&lt;String&gt; names = <\/strong><strong>new<\/strong><strong> ArrayList&lt;&gt;();<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>\/\/ 2. ArrayList with initial capacity<\/strong><strong><br><\/strong><strong>ArrayList&lt;Integer&gt; scores = <\/strong><strong>new<\/strong><strong> ArrayList&lt;&gt;(50);<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>\/\/ 3. ArrayList from another collection<\/strong><strong><br><\/strong><strong>List<\/strong><strong>&lt;String&gt; source = Arrays.asList(<\/strong><strong>&#8220;Alice&#8221;<\/strong><strong>, <\/strong><strong>&#8220;Bob&#8221;<\/strong><strong>, <\/strong><strong>&#8220;Carol&#8221;<\/strong><strong>);<\/strong><strong><br><\/strong><strong>ArrayList&lt;String&gt; copy = <\/strong><strong>new<\/strong><strong> ArrayList&lt;&gt;(source);<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>\/\/ 4. ArrayList initialized inline (Java 9+)<\/strong><strong><br><\/strong><strong>List<\/strong><strong>&lt;String&gt; immutable = <\/strong><strong>List<\/strong><strong>.of(<\/strong><strong>&#8220;X&#8221;<\/strong><strong>, <\/strong><strong>&#8220;Y&#8221;<\/strong><strong>, <\/strong><strong>&#8220;Z&#8221;<\/strong><strong>);<\/strong><strong><br><\/strong><strong>ArrayList&lt;String&gt; mutable = <\/strong><strong>new<\/strong><strong> ArrayList&lt;&gt;(immutable);<\/strong><strong><br><\/strong><strong>&nbsp;<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Core Methods of ArrayList in Java<\/strong><\/h2>\n\n\n\n<p>ArrayList in Java provides a rich set of built-in methods. Here are the most commonly used ones, each with a practical code example.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Adding Elements<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>ArrayList&lt;String&gt; fruits = <\/strong><strong>new<\/strong><strong> ArrayList&lt;&gt;();<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>fruits.add(<\/strong><strong>&#8220;Apple&#8221;<\/strong><strong>); &nbsp; &nbsp; &nbsp; <\/strong><strong><\/strong><strong>\/\/ Add to end \u2192 [Apple]<\/strong><strong><br><\/strong><strong>fruits.add(<\/strong><strong>&#8220;Banana&#8221;<\/strong><strong>);&nbsp; &nbsp; &nbsp; <\/strong><strong><\/strong><strong>\/\/ Add to end \u2192 [Apple, Banana]<\/strong><strong><br><\/strong><strong>fruits.add(0, <\/strong><strong>&#8220;Mango&#8221;<\/strong><strong>);&nbsp; &nbsp; <\/strong><strong><\/strong><strong>\/\/ Add at index 0 \u2192 [Mango, Apple, Banana]<\/strong><strong><br><\/strong><strong>fruits.addAll(Arrays.asList(<\/strong><strong>&#8220;Grape&#8221;<\/strong><strong>, <\/strong><strong>&#8220;Kiwi&#8221;<\/strong><strong>));&nbsp; <\/strong><strong>\/\/ Add multiple<\/strong><strong><br><\/strong><strong>\/\/ Result: [Mango, Apple, Banana, Grape, Kiwi]<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Accessing Elements<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>String first = fruits.get(0); &nbsp; \/\/ &#8220;Mango&#8221; &#8212; O(1)<br>int size = fruits.size();&nbsp; &nbsp; \/\/ 5<br>int idx&nbsp; = fruits.indexOf(&#8220;Banana&#8221;);&nbsp; \/\/ 2<br>boolean has&nbsp; = fruits.contains(&#8220;Kiwi&#8221;); &nbsp; \/\/ true<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Updating Elements<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>fruits.set(1, &#8220;Papaya&#8221;); &nbsp; \/\/ Replace index 1: [Mango, Papaya, Banana, Grape, Kiwi]<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Removing Elements<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>fruits.remove(&#8220;Grape&#8221;); \/\/ Remove by value \u2192 [Mango, Papaya, Banana, Kiwi]<br>fruits.remove(0); &nbsp; &nbsp; &nbsp; \/\/ Remove by index \u2192 [Papaya, Banana, Kiwi]<br>fruits.clear(); &nbsp; &nbsp; &nbsp; &nbsp; \/\/ Remove all \u2192 []<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. Iterating an ArrayList<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>ArrayList&lt;String&gt; cities = <\/strong><strong>new<\/strong><strong> ArrayList&lt;&gt;(Arrays.asList(<\/strong><strong>&#8220;Delhi&#8221;<\/strong><strong>, <\/strong><strong>&#8220;Mumbai&#8221;<\/strong><strong>, <\/strong><strong>&#8220;Chennai&#8221;<\/strong><strong>));<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>\/\/ Method 1: for-each loop (recommended for read-only iteration)<\/strong><strong><br><\/strong><strong>for<\/strong><strong> (String city : cities) {<\/strong><strong><br><\/strong><strong>&nbsp; &nbsp; System.out.println(city);<\/strong><strong><br><\/strong><strong>}<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>\/\/ Method 2: index-based for loop (when index matters)<\/strong><strong><br><\/strong><strong>for<\/strong><strong> (int i = 0; i &lt; cities.size(); i++) {<\/strong><strong><br><\/strong><strong>&nbsp; &nbsp; System.out.println(i + <\/strong><strong>&#8220;: &#8220;<\/strong><strong> + cities.get(i));<\/strong><strong><br><\/strong><strong>}<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>\/\/ Method 3: Iterator (safe removal during iteration)<\/strong><strong><br><\/strong><strong>Iterator&lt;String&gt; it = cities.iterator();<\/strong><strong><br><\/strong><strong>while<\/strong><strong> (it.hasNext()) {<\/strong><strong><br><\/strong><strong>&nbsp; &nbsp; <\/strong><strong>if<\/strong><strong> (it.next().equals(<\/strong><strong>&#8220;Mumbai&#8221;<\/strong><strong>)) it.remove();<\/strong><strong><br><\/strong><strong>}<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>\/\/ Method 4: forEach with lambda (Java 8+)<\/strong><strong><br><\/strong><strong>cities.<\/strong><strong>forEach<\/strong><strong>(city -&gt; System.out.println(city));<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>6. Sorting an ArrayList<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><strong>import java.. Collections;<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>ArrayList&lt;Integer&gt; nums = <\/strong><strong>new<\/strong><strong> ArrayList&lt;&gt;(Arrays.asList(5, 2, 8, 1, 9, 3));<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>Collections. sort(nums);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <\/strong><strong><\/strong><strong>\/\/ [1, 2, 3, 5, 8, 9]<\/strong><strong><br><\/strong><strong>Collections. sort(nums, Collections.reverseOrder()); <\/strong><strong>\/\/ [9, 8, 5, 3, 2, 1]<\/strong><strong><br><\/strong><strong> <\/strong><strong><br><\/strong><strong>\/\/ Sort strings by length (custom Comparator)<\/strong><strong><br><\/strong><strong>ArrayList&lt;String&gt; words = <\/strong><strong>new<\/strong><strong> ArrayList&lt;&gt;(Arrays.asList(<\/strong><strong>&#8220;Banana&#8221;<\/strong><strong>, <\/strong><strong>&#8220;Apple&#8221;<\/strong><strong>, <\/strong><strong>&#8220;Fig&#8221;<\/strong><strong>));<\/strong><strong><br><\/strong><strong>words.sort((a, b) -&gt; a.length() &#8211; b.length());&nbsp; <\/strong><strong>\/\/ [Fig, Apple, Banana]<\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><strong>Read More: <\/strong><a href=\"https:\/\/www.guvi.in\/blog\/sorting-in-data-structure-categories-types\/\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>Sorting in data structure<\/strong><\/a><\/p>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 800px;\">\n  <strong style=\"font-size: 22px; color: #FFFFFF;\">\ud83d\udca1 Did You Know?<\/strong>\n  <p style=\"margin-top: 14px;\">\n    The <strong>ArrayList<\/strong> in Java, Python\u2019s <strong>list<\/strong>, and C#\u2019s <strong>List&lt;T&gt;<\/strong> all use a similar underlying strategy for dynamic resizing. When the internal array becomes full, the data structure allocates a new array with increased capacity (typically growing by a factor of around <strong>1.5\u00d7 to 2\u00d7<\/strong>) and copies existing elements into it. This approach enables efficient dynamic growth while keeping performance predictable. Although individual resize operations are <strong>O(n)<\/strong>, the amortized cost of performing <strong>n append operations remains O(n)<\/strong>, ensuring that average insertion performance stays constant over time rather than degrading to quadratic complexity.\n  <\/p>\n<\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Real-World Example of ArrayList in Java<\/strong><\/h2>\n\n\n\n<p>Let&#8217;s walk through a practical example: an e-commerce shopping cart to see how ArrayList in Java works in a real application.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td>import java.util.ArrayList;<br>import java.util.Collections;<br><br><strong>class<\/strong> <strong>Product<\/strong> {<br>&nbsp; &nbsp; String name;<br>&nbsp; &nbsp; double price;<br>&nbsp; &nbsp; Product(String name, double price) {<br>&nbsp; &nbsp; &nbsp; &nbsp; this.name = name;<br>&nbsp; &nbsp; &nbsp; &nbsp; this.price = price;<br>&nbsp; &nbsp; }<br>&nbsp; &nbsp; <strong>public<\/strong> String toString() { <strong>return<\/strong> name + &#8221; (\u20b9&#8221; + price + &#8220;)&#8221;; }<br>}<br><br><strong>class<\/strong> <strong>ShoppingCart<\/strong> {<br>&nbsp; &nbsp; <strong>private<\/strong> ArrayList&lt;Product&gt; items = <strong>new<\/strong> ArrayList&lt;&gt;();<br><br>&nbsp; &nbsp; <strong>public<\/strong> void addItem(Product p) { items.add(p); }<br><br>&nbsp; &nbsp; <strong>public<\/strong> void removeItem(String name) {<br>&nbsp; &nbsp; &nbsp; &nbsp; items.removeIf(p -&gt; p.name.equals(name));<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; <strong>public<\/strong> double totalPrice() {<br>&nbsp; &nbsp; &nbsp; &nbsp; <strong>return<\/strong> items.stream().mapToDouble(p -&gt; p.price).sum();<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; <strong>public<\/strong> void sortByPrice() {<br>&nbsp; &nbsp; &nbsp; &nbsp; items.sort((a, b) -&gt; Double.compare(a.price, b.price));<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; <strong>public<\/strong> void display() { items.<strong>forEach<\/strong>(System.out::println); }<br>}<br><br>\/\/ Usage<br>ShoppingCart cart = <strong>new<\/strong> ShoppingCart();<br>cart.addItem(<strong>new<\/strong> Product(&#8220;Laptop&#8221;, 75000));<br>cart.addItem(<strong>new<\/strong> Product(&#8220;Mouse&#8221;,&nbsp; 850));<br>cart.addItem(<strong>new<\/strong> Product(&#8220;Keyboard&#8221;, 2200));<br>cart.sortByPrice();<br>cart.display();<br>System.out.println(&#8220;Total: \u20b9&#8221; + cart.totalPrice());<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>This pattern of storing a dynamic collection of objects, adding and removing entries at runtime, and sorting by a custom criterion is exactly how ArrayList in Java is used in production systems like order management platforms, inventory trackers, and student grade books.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Mistakes When Using ArrayList in Java<\/strong><\/h2>\n\n\n\n<p><strong>1. Using raw types instead of generics: <\/strong>Writing ArrayList list = new ArrayList() without a type parameter is legal but dangerous. It disables compile-time type checking, meaning you can accidentally add the wrong type and only discover it at runtime as a ClassCastException. Always declare the type: ArrayList&lt;String&gt;.<\/p>\n\n\n\n<p><strong>2. Removing elements by index inside a for loop: <\/strong>Calling list.remove(i) inside a forward-running for loop causes elements to shift left, making you skip the element immediately after the removed one. Use an Iterator with it.remove(), iterate backwards, or use removeIf() for safe removal.<\/p>\n\n\n\n<p><strong>3. Confusing remove(int index) and remove(Object element): <\/strong>ArrayList has two overloaded remove methods. For an ArrayList&lt;Integer&gt;, list.remove(2) removes the element at index 2, not the Integer value 2. To remove the value 2, use list. remove(Integer.valueOf(2)).<\/p>\n\n\n\n<p><em>Want to master Java collections, object-oriented programming, DSA, and system design with real projects and placement support? Check out <a href=\"https:\/\/www.guvi.in\/courses\/programming\/java-programming\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=ArrayList+in+Java%3A+A+Complete+Guide\" target=\"_blank\" rel=\"noreferrer noopener\"><strong>HCL GUVI&#8217;s Java Development Programme<\/strong><\/a> built for students and working professionals who want to build job-ready Java skills with hands-on mentorship.<\/em><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>ArrayList is a fundamental Java collection that every developer should understand beyond basic operations. Knowing how it handles dynamic resizing, when to use it instead of LinkedList, and how to modify it safely during iteration helps you write more efficient, reliable, and interview-ready Java code.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQ<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1781496984190\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">1.\u00a0 \u00a0 <strong>What is ArrayList in Java?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>ArrayList in Java is a resizable array implementation of the List interface in the java.util package. It stores elements in insertion order, allows duplicates and null values, supports O(1) random access by index, and automatically resizes its internal array when capacity is exceeded.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1781496989732\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">2.\u00a0 \u00a0 <strong>What is the difference between ArrayList and Array in Java?\u00a0<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A Java array has a fixed size declared at creation time, while an ArrayList grows and shrinks dynamically. Arrays can hold primitives directly, but ArrayList only holds objects (using wrapper types like Integer for int).\u00a0\u00a0<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1781496997426\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">3.\u00a0 <strong>What is the default initial capacity of ArrayList in Java?\u00a0<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The default initial capacity of ArrayList in Java is 10. When elements are added beyond this capacity, ArrayList creates a new internal array approximately 1.5 times the current size and copies all elements into it.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1781497007837\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">4.\u00a0 \u00a0 <strong>How does ArrayList resize itself in Java?<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>When an element is added and the internal array is full, ArrayList calculates a new capacity as oldCapacity + oldCapacity \/ 2 (approximately 1.5x growth), allocates a new array of that size, copies all existing elements using Arrays.copyOf(), and then adds the new element.\u00a0\u00a0<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1781497021303\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">5.\u00a0 \u00a0 <strong>Is ArrayList in Java thread-safe?\u00a0<\/strong><\/h3>\n<div class=\"rank-math-answer \">\n\n<p>No, ArrayList is not thread-safe by default. If multiple threads read and write to the same ArrayList simultaneously without synchronization, it can lead to data corruption.\u00a0<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>ArrayList in Java solves the limitation of fixed-size arrays by providing a dynamic list that automatically resizes as needed. It combines the flexibility of dynamic storage with fast array-based access and offers many built-in methods for managing data efficiently.&nbsp; Quick TL;DR What is ArrayList in Java? ArrayList in Java is a class in the java.util [&hellip;]<\/p>\n","protected":false},"author":63,"featured_media":116941,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[720],"tags":[],"views":"25","authorinfo":{"name":"Vishalini Devarajan","url":"https:\/\/www.guvi.in\/blog\/author\/vishalini\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/06\/what-is-arraylist-in-java-300x115.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/116406"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=116406"}],"version-history":[{"count":3,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/116406\/revisions"}],"predecessor-version":[{"id":116942,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/116406\/revisions\/116942"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/116941"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=116406"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=116406"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=116406"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}