Thuta Learning
IntermediateProgrammingbeginner

Arrays

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

An array is a structure that lets you store many values of the same data type in a single variable. Indexing starts at 0, meaning you grab the first item with items[0]. Beginners often grumble, "Shouldn't the first one be 1?" — but in the programming world, 0 gets VIP treatment.

java
public class Main {
  public static void main(String[] args) {
    String[] courses = {"HTML", "CSS", "Java", "Python"};

    System.out.println(courses[0]);
    courses[2] = "Advanced Java";
    System.out.println(courses[2]);
    System.out.println("Total courses: " + courses.length);

    for (int i = 0; i < courses.length; i++) {
      System.out.println((i + 1) + ". " + courses[i]);
    }
  }
}

courses array stores 4 course names. courses[0] grabs the first item. courses[2] gets updated with a new value. A loop then prints out every item in the array.

You should see
HTML Advanced Java Total courses: 4 1. HTML 2. CSS 3. Advanced Java 4. Python

Real-World Use

Arrays are great for fixed collections like student marks, product names, menu items, settings lists, or game scores.

Easy traps

  • Trying to access courses[4] will throw an error — even though there are 4 items, the valid indexes are only 0, 1, 2, and 3.
Arrays | Thuta Learning