📚 Arrays and Collections - Your Data Organization Toolkit

🎯 Learning Objectives


🗂️ Arrays - Your First Data Container

Visual representation of 2D arrays in Java showing rows and columns structure

📊 What is an Array?

Think of an array like apartment building with numbered units:

Array memory layout diagram showing contiguous memory allocation

// Real-world example: Student grades
int[] studentGrades = new int[5];  // Building with 5 apartments
//  [0] [1] [2] [3] [4]  ← Index numbers (addresses)
//  [ 0][ 0][ 0][ 0][ 0]  ← Default values

🏗️ Array Declaration and Initialization

2D Array visualization using lockers - rows and columns concept

// 🎬 Movie Theater Example
// Method 1: Declare then initialize
String[] movieTitles;                    // Just declare the variable
movieTitles = new String[3];             // Create array of size 3

// Method 2: Declare and initialize together
String[] topMovies = {"Inception", "Avatar", "Titanic"};

// Method 3: Anonymous array (useful for method parameters)
String[] newReleases = new String[]{"Spider-Man", "Batman", "Superman"};

// 🎮 Gaming Score Example - Multidimensional Arrays
int[][] gameScores = {
    {100, 200, 150},  // Player 1 scores (3 levels)
    {180, 220, 190},  // Player 2 scores
    {95,  175, 200}   // Player 3 scores
};

<aside> 💡

Real-World Analogy: Think of a 2D array like a spreadsheet: