One question, one focus

Common Interview Questions

Master the most frequently asked technical interview questions

Choose another question · 32

Choose a question to practice

32 / 32 questions

Data Structures & Algorithms 1 / 32

What is the difference between Array and ArrayList in Java?

Example answer and explanationLink to this question

Key Differences:

1. Size:

Array: Fixed size, must be specified at creation

ArrayList: Dynamic size, grows automatically

2. Type:

Array: Can hold primitives (int, char) and objects

ArrayList: Can only hold objects (uses wrapper classes for primitives)

3. Performance:

Array: Faster for fixed-size collections

ArrayList: Slightly slower due to resizing overhead

4. Methods:

Array: No built-in methods, only length property

ArrayList: Rich API with add(), remove(), contains(), etc.

Example:

// Array

int[] arr = new int[5];

arr[0] = 10;

// ArrayList

ArrayList<Integer> list = new ArrayList<>();

list.add(10);

list.add(20);

When to use:

Use Array when size is known and fixed

Use ArrayList when size varies or you need built-in methods

AI engineering: 50 questions and answer rubrics →