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. PythonReal-World Use
Arrays are great for fixed collections like student marks, product names, menu items, settings lists, or game scores.