Thuta Learning
AdvancedProgrammingbeginner

ArrayList

Relax. We'll talk through this in plain words — no textbook voice.

ArrayList is a Java Collection you can use like a resizable array. A regular array has a fixed size, but an ArrayList lets you add and remove items freely. When you need a dynamic list, ArrayList is much more convenient.

java
import java.util.ArrayList;

public class Main {
  public static void main(String[] args) {
    ArrayList<String> tasks = new ArrayList<String>();

    tasks.add("Learn Java syntax");
    tasks.add("Practice loops");
    tasks.add("Build mini project");

    tasks.remove("Practice loops");

    System.out.println(tasks);
    System.out.println("First task: " + tasks.get(0));
    System.out.println("Total tasks: " + tasks.size());
  }
}

ArrayList here is a dynamic list holding String values. You add items with add() and remove them with remove(). get(0) grabs the first item, and size() gives you the item count.

You should see
[Learn Java syntax, Build mini project] First task: Learn Java syntax Total tasks: 2

Real-World Use

ArrayList is used for dynamic lists like todo lists, shopping cart items, student lists, notifications, and search results.

Easy traps

  • Using tasks.length on an ArrayList is wrong — you need tasks.size().
ArrayList | Thuta Learning