Ch 9 · Arrays & Lists · Java

Topic 9 of 13 in Java — Complete Tutorial (Beginner) — 3 lessons.

Arrays

An array stores many values of the same type together under one name. In Java, an array has a fixed size set when you create it, and every item has an index starting from 0. So an array of 5 items has valid indices 0 to 4. You get the number of items with .length (no brackets). Arrays are perfect when you know exactly how many values you need to store.

ArrayList: A Growable List

A plain array cannot change size. When you need a list that grows and shrinks, Java provides ArrayList. You add items with .add(), read them with .get(index), remove with .remove(), and find the size with .size(). An ArrayList holds objects, so for whole numbers you use Integer (the object version of int). This is one of the most-used tools in everyday Java.

Processing Arrays

The most common task with a collection is processing every element — summing, finding the largest, or counting matches. You loop over the items and combine them into a result. The example sums an array, finds the average, and locates the highest value by hand — patterns you will use again and again.

All topics in Java Beginner

  1. Introduction to Programming & Java
  2. Your First Java Program
  3. Variables — Your Data Containers
  4. Data Types — Kinds of Values
  5. Operators & Expressions
  6. Conditional Statements
  7. Loops & Iterations
  8. Methods
  9. Arrays & Lists
  10. Objects & Classes
  11. Strings — Working with Text
  12. Exception Handling
  13. Mini-Projects & Practice