Java ArrayList Examples

This page contains 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 -

  • 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.
  • ArrayList internally uses an array to store the elements. Just like arrays, It allows you to retrieve the elements by their index.
  • Java ArrayList allows duplicate and null values.
  • Java ArrayList is an ordered collection. It maintains the insertion order of the elements.
  • You cannot create an ArrayList of primitive types like int, char etc. You need to use boxed types like Integer, Character, Boolean etc.
  • 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.
The below is ArrayList class diagram:

Java ArrayList Source Code Examples

  1. Sort List of Integers in Ascending and Descending Order Example
  2. List (ArrayList) Iterator Example
  3. Create the Immutable ArrayList with List.of() Method Example
  4. Create Immutable ArrayList with Collections.unmodifiableList() Exmaple
  5. Java 10 - Copy List into Another List Exmaple
  6. Java 8 - Copy List into Another List Example
  7. Java - Copy a List to Another List using Collections.copy() method
  8. Java - Copy a List to Another List Example
  9. Java ArrayList spliterator() Method Example
  10. Java ArrayList sort() Method Example
  11. Java ArrayList retainAll() Method Example
  12. Java ArrayList removeIf() Method Example
  13. Java ArrayList removeAll() Method Example
  14. Java ArrayList remove() Method Example
  15. Java ArrayList lastIndexOf() Method Example
  16. Java ArrayList isEmpty() Method Example
  17. Java util ArrayList indexOf() Method Example
  18. Java ArrayList get() Method Example
  19. Java ArrayList ensureCapacity() Method Example
  20. Java ArrayList contains() Method Example
  21. Java ArrayList clone() Method Example
  22. Java ArrayList clear() Method Example
  23. Java ArrayList addAll() Method Example
  24. Java ArrayList add() Method Example
  25. Java 8 forEach() List Example
  26. Add Enum Values to ArrayList Example
  27. Join List Strings with Commas in Java
  28. Java Stream filter null values example
  29. Java ArrayList subList() Example
  30. Get Index of Elements in ArrayList Example
  31. Java ArrayList removeIf() Example
  32. Java ArrayList add(), get() and set() Method Example
  33. Iterate over ArrayList Using forEach Java
  34. Iterate over ArrayList using Iterator in Java
  35. Java ArrayList indexOf() and lastIndexOf() Example
  36. Search an Element in an ArrayList in Java
  37. Clear ArrayList in Java Example
  38. Java ArrayList removeAll() Method Example
  39. Java ArrayList remove() Method Example
  40. How to Iterate over ArrayList in Java
  41. How to Remove Element from ArrayList in Java
  42. How to Access Elements of ArrayList in Java
  43. Create ArrayList from Another ArrayList in Java
  44. How to Create an ArrayList and Add Elements to It