What is the difference between an array and an ArrayList in Java?

PointArrayArrayList
SizeFixedDynamic
TypesPrimitives and objectsObjects only (use wrappers)
Lengtharr.lengthlist.size()
Add or removeNot possibleadd(), remove()
GenericsNoYes
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        int[] arr = new int[3];
        List<Integer> list = new ArrayList<>();
        list.add(10);
        list.add(20);
        System.out.println(arr.length + " " + list.size());
    }
}
Output

3 2

See Java Arrays and Java ArrayList.


Learn more about the similar topics:
Tutorials
Java ArrayList
Java HashMap
Java HashSet and LinkedList
Java Generics
Exercises & Assignments
Sort a list of students with a Comparator
Count the frequency of words with a HashMap
Remove duplicates from a list and keep the order
Interview Questions & Answers
What is the difference between an array and an ArrayList in Java?
How does HashMap work internally in Java?
What is the difference between HashMap, Hashtable and ConcurrentHashMap?
Why must you override both equals() and hashCode() in Java?
What is the difference between Comparable and Comparator in Java?
What is the difference between ArrayList and LinkedList in Java?
What is the difference between fail-fast and fail-safe iterators?