Java ArrayList Examples
Published: 2021-11-17 07:16:18

This page contains 40+ source code examples of the ArrayList class in Java.

On this page, we will learn everything about the Java ArrayList class with source code examples. We will learn about different ArrayList operations and methods with the help of coding examples.

Following are few key points to note about ArrayList in Java -

1. An ArrayList is a re-sizable array, also called a dynamic array. It grows its size to accommodate new elements and shrinks the size when the elements are removed.

2. ArrayList internally uses an array to store the elements. Just like arrays, It allows you to retrieve the elements by their index.

3. Java ArrayList allows duplicate and null values.
Java ArrayList is an ordered collection. It maintains the insertion order of the elements.
4. You cannot create an ArrayList of primitive types like int, char etc. You need to use boxed types like Integer, Character, Boolean etc.
5. Java ArrayList is not synchronized. If multiple threads try to modify an ArrayList at the same time, then the final outcome will be non-deterministic. You must explicitly synchronize access to an ArrayList if multiple threads are gonna modify it.

# Java ArrayList Examples

<ol style="text-align: left;"><li><a href="https://www.sourcecodeexamples.net/2020/04/sort-list-of-integers-in-ascending-and.html" target="_blank">Sort List of Integers in Ascending and Descending Order Example</a></li><li><a href="https://www.sourcecodeexamples.net/2020/03/list-arraylist-iterator-example.html" target="_blank">List (ArrayList) Iterator Example</a></li><li><a href="https://www.sourcecodeexamples.net/2020/03/create-immutable-arraylist-with-listof.html" target="_blank">Create the Immutable ArrayList with List.of() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2020/03/create-immutable-arraylist-with.html" target="_blank">Create Immutable ArrayList with Collections.unmodifiableList() Exmaple</a></li><li><a href="https://www.sourcecodeexamples.net/2020/02/java-10-copy-list-into-another-list.html" target="_blank">Java 10 - Copy List into Another List Exmaple</a></li><li><a href="https://www.sourcecodeexamples.net/2020/02/java-8-copy-list-into-another-list.html" target="_blank">Java 8 - Copy List into Another List Example</a></li><li><a href="https://www.sourcecodeexamples.net/2020/02/java-copy-list-to-another-list-using.html" target="_blank">Java - Copy a List to Another List using Collections.copy() method</a></li><li><a href="https://www.sourcecodeexamples.net/2020/02/java-copy-list-to-another-list-example.html" target="_blank">Java - Copy a List to Another List Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-spliterator-method.html" target="_blank">Java ArrayList spliterator() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-sort-method-example.html" target="_blank">Java ArrayList sort() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-retainall-method-example.html" target="_blank">Java ArrayList retainAll() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-removeif-method-example.html" target="_blank">Java ArrayList removeIf() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-removeall-method-example.html" target="_blank">Java ArrayList removeAll() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-remove-method-example.html" target="_blank">Java ArrayList remove() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-lastindexof-method.html" target="_blank">Java ArrayList lastIndexOf() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-isempty-method-example.html" target="_blank">Java ArrayList isEmpty() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-util-arraylist-indexof-method.html" target="_blank">Java util ArrayList indexOf() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-get-method-example.html" target="_blank">Java ArrayList get() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-ensurecapacity-method.html" target="_blank">Java ArrayList ensureCapacity() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-contains-method-example.html" target="_blank">Java ArrayList contains() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-clone-method-example.html" target="_blank">Java ArrayList clone() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-clear-method-example.html" target="_blank">Java ArrayList clear() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-addall-method-example.html" target="_blank">Java ArrayList addAll() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/12/java-arraylist-add-method-example.html" target="_blank">Java ArrayList add() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/11/java-8-foreach-list-example.html" target="_blank">Java 8 forEach() List Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/07/add-enum-values-to-arraylist-example.html" target="_blank">Add Enum Values to ArrayList Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/07/join-list-strings-with-commas-in-java.html" target="_blank">Join List Strings with Commas in Java</a></li><li><a href="https://www.sourcecodeexamples.net/2019/07/java-stream-filter-null-values-example.html" target="_blank">Java Stream filter null values example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/java-arraylist-sublist-example.html" target="_blank">Java ArrayList subList() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/get-index-of-elements-in-arraylist.html" target="_blank">Get Index of Elements in ArrayList Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/java-arraylist-removeif-example.html" target="_blank">Java ArrayList removeIf() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/java-arraylist-add-get-and-set-method.html" target="_blank">Java ArrayList add(), get() and set() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/iterate-over-arraylist-using-foreach.html" target="_blank">Iterate over ArrayList Using forEach Java</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/iterate-over-arraylist-using-iterator.html" target="_blank">Iterate over ArrayList using Iterator in Java</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/java-arraylist-indexof-and-lastindexof.html" target="_blank">Java ArrayList indexOf() and lastIndexOf() Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/search-element-in-arraylist-in-java.html" target="_blank">Search an Element in an ArrayList in Java</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/clear-arraylist-in-java-example.html" target="_blank">Clear ArrayList in Java Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/java-arraylist-removeall-method-example.html" target="_blank">Java ArrayList removeAll() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/java-arraylist-remove-method-example.html" target="_blank">Java ArrayList remove() Method Example</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/how-to-iterate-over-arraylist-in-java.html" target="_blank">How to Iterate over ArrayList in Java</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/how-to-remove-element-from-arraylist-in-java.html" target="_blank">How to Remove Element from ArrayList in Java</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/how-to-access-elements-of-arraylist-in-java.html" target="_blank">How to Access Elements of ArrayList in Java</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/create-arraylist-from-another-arraylist.html" target="_blank">Create ArrayList from Another ArrayList in Java</a></li><li><a href="https://www.sourcecodeexamples.net/2019/06/how-to-create-arraylist-and-add-elements-to-it.html" target="_blank">How to Create an ArrayList and Add Elements to It</a></li></ol>

# Original Post
<a href="https://www.sourcecodeexamples.net/p/java-arraylist-examples.html" target="_blank">Java ArrayList Examples</a>