🚂 Arrays Explained Like You're 5

Published: (January 18, 2026 at 05:22 PM EST)
1 min read
Source: Dev.to

Source: Dev.to

The Train

Imagine a train with numbered compartments:

🚂 [Car 0] [Car 1] [Car 2] [Car 3] [Car 4]

Each car has a number (starting from 0!) and can hold one thing.

Arrays are trains for your data!

Full deep‑dive with code examples

In Code

fruits = ["apple", "banana", "cherry", "date"]
Index:    0         1          2        3
       ["apple", "banana", "cherry", "date"]

To get banana: fruits[1] (index 1, the second item)

Why Start at 0?

Tradition from early computers! Just remember:

  • First item = index 0
  • Second item = index 1
  • Third item = index 2

What Can You Do?

ActionCodeResult
Get itemfruits[2]"cherry"
Change itemfruits[0] = "apricot"Updates first item
Add itemfruits.append("elderberry")Adds to end
Countlen(fruits)5

In One Sentence

Arrays store multiple items in a numbered list, like numbered train compartments in a row.

Back to Blog

Related posts

Read more »

Day 1 of DSA: Arrays Fundamentals

Day 1: Arrays I chose arrays as the starting point for my DSA journey. Although I am not a complete beginner—I have learned Java and basic DSA earlier—I felt a...