Single logo
  • Courses
  • Blog
  • About
Join on SkoolJoin on Skool

In this topic

Java
  • Install Java 25 (JDK) and IntelliJ IDEA, Then Run Your First Program
  • Use Claude Agent, Copilot or Junie Inside IntelliJ IDEA
  • Java Hello World with Maven: What the JDK Does and What Maven Adds
  • Java Variables, Keywords and Naming Rules
  • Maven in IntelliJ: pom.xml, Dependencies and the Build Lifecycle
  • Java Primitive Types and Memory: What int x = 5 Really Does
  • Java Strings and Text Blocks: Quotes, Concatenation and parseInt
  • Java Operators: Arithmetic, a++ vs ++a, Precedence, && || and the Ternary
  • Java Type Casting: Widening, Narrowing and Converting Text to Numbers
  • Java Practice Lab: A Cafe Bill with Variables, Operators and Casting
  • Java if, else and switch: Braces, Else-If Ladders and the Modern Switch
  • Java Loops: for, while, do-while and for-each
  • Java break, continue and Nested Loops
  • What's New in Java 21 to 25: Compact Source Files and Sequenced Collections
  • Java Arrays: Indexes, Default Values, Loops and 2D Grids
  • Java Methods and Overloading: Parameters, return and Pass-by-Value
  • Java Scope, Code Blocks and the Call Stack
  • Read User Input in Java with Scanner (and the Leftover Enter Trap)
  • Java Practice Lab: A Gym Weekly Tracker with Loops, Arrays and Methods
  • Debugging Java in IntelliJ: Stack Traces, Breakpoints and a Better AI Prompt
  • Java var: Let Java Infer the Type
  • Push and Pull in IntelliJ: Two Developers, One GitHub Repository, a Rejected Push and a Conflict
  • Java Classes and Objects: One Blueprint, Many Cars
  • Java Constructors and the this Keyword
  • Java Instance Methods, Getters, Setters and toString
  • Java static: Fields, Methods and Blocks Shared by the Whole Class
  • Java Packages and Imports: Every Class Has an Address
  • Java Access Modifiers and Encapsulation: Private Data, Public Methods
  • Java final and Immutable Objects: Assign Once, Share Safely
  • Java Strings as Objects: The String Pool, == vs equals, StringBuilder and printf
  • Java Practice Lab: A Library Book Catalogue with final Fields and StringBuilder
  • Java Inheritance: extends, super and the Order Objects Are Built
  • Java Method Overriding, @Override and the Object Class
  • Java Polymorphism: Upcasting, Dynamic Dispatch and Downcasting
  • Java Composition: Has-A vs Is-A
  • Java Abstract Classes: A Parent That Leaves One Blank
  • Java Interfaces: Contracts and Multiple Inheritance
  • Java Nested, Inner and Anonymous Classes
  • Java Enums with Fields, Methods and switch
  • Java Practice Lab: Payment Processing with an Interface, an Abstract Class and an Enum
  • Java Records: A Whole Data Class in One Line
  • Java Sealed Classes and Interfaces
  • Java Pattern Matching with instanceof and switch
  • Java Record Patterns: Unpacking a Record
  • Java equals and hashCode: Why a HashSet Needs Both
  • From Arrays to Collections: The Java Collections Framework Map
  • Java Wrapper Classes and Autoboxing
  • Java ArrayList: The Stretchy Array
  • Java LinkedList vs ArrayList: Nodes or an Array
  • Java Sets: HashSet, LinkedHashSet and TreeSet
  • Java Sorting with Comparable and Comparator
  • Java Maps: HashMap, LinkedHashMap and TreeMap
  • Java Stacks, Queues and Deques: ArrayDeque and PriorityQueue
  • Choosing a Java Collection: Immutable and Sequenced Collections
  • Java Exception Handling: try, catch and finally
  • Java throw, throws, Checked vs Unchecked and Custom Exceptions
  • Java try-with-resources and Clean Error Handling
  • Java Generics: Type-Safe Containers
  • Java Generic Methods, Bounded Types and Wildcards
  • Java Lambdas and Functional Interfaces
  • Java Built-in Functional Interfaces: Predicate, Function, Consumer, Supplier
  • Java Optional: Saying Maybe Without null
  • Java Streams I: filter, map and reduce
  • Java Streams II: Collectors, groupingBy and flatMap
  • Why Concurrency: Processes, Threads and the Main Thread in Java
  • Creating Threads in Java: Thread, Runnable and Lambdas
  • Java Thread Lifecycle: sleep, join and interrupt
  • Java Race Conditions and synchronized
  • Java volatile and Atomic Variables
  • Java ExecutorService and Thread Pools
  • Java Callable, Future and CompletableFuture
  • Java Locks, Deadlock and tryLock
  • Java Concurrent Collections and Virtual Threads
  • Why Slow Work Belongs off the Request Thread: 202 Accepted and a Job Id in Spring Boot
  • Virtual Threads in Spring Boot: One Property, and the Connection Pool Trap
  • @Async, Named TaskExecutors and Structured Concurrency in Spring Boot
  • Java Files and Directories with NIO.2: Path and Files
  • Reading and Writing Text Files in Java
  • Java Structured Data: Reading and Writing JSON and CSV
  1. Blog
  2. /
  3. Java
  4. /
  5. Collections

From Arrays to Collections: The Java Collections Framework Map

An array of 3 students can't seat John, so Java throws Index 3 out of bounds. A List just grows. Then the map of the framework: List, Set and Queue under Collection, Map beside it, four behaviours in one program, and why the variable type should be the interface.

Chaand Sheikh

·27 November 2026·Updated 28 November 2026Collections

What you will learn

  • Explain why a fixed-size array can't take one more value
  • Create a List that grows as you add
  • Name the Collection interfaces List, Set and Queue, Map beside them, and their main classes
  • Declare collections with the interface type so one method accepts any List

Before you start

  • Java arrays
  • Java interfaces

Arrays have one problem: their size is fixed. A list just grows when you add to it. This article shows the problem, the fix, and a map of the whole collections family you'll meet in the next lessons.

An array cannot grow

package org.studyeasy.s04l01;

public class Ex01_ArrayIsFull {
    public static void main(String[] args) {
        String[] students = new String[3];   // size fixed at 3
        students[0] = "Asha";
        students[1] = "Ravi";
        students[2] = "Meera";
        try {
            students[3] = "John";            // a 4th student joins
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("No room: " + e.getMessage());
        }
        System.out.println("Students: " + students.length);
    }
}
No room: Index 3 out of bounds for length 3
Students: 3

new String[3] sets aside three slots, and that size is fixed the moment the array is created. The seats are 0, 1 and 2, so index 3 doesn't exist. Java throws an exception, the catch prints it, and the array still holds three.

A list just grows

package org.studyeasy.s04l01;

import java.util.ArrayList;
import java.util.List;

public class Ex02_ListGrows {
    public static void main(String[] args) {
        List<String> students = new ArrayList<>();  // starts empty
        students.add("Asha");
        students.add("Ravi");
        students.add("Meera");
        students.add("John");                       // it just grows
        System.out.println(students);
        System.out.println("Students: " + students.size());
    }
}
[Asha, Ravi, Meera, John]
Students: 4

List<String> is a list of Strings, and it starts empty. There's no size to choose. Each add puts a name at the end, and when John arrives the list makes room on its own. size() says 4.

The family: Collection, and Map beside it

The Collection interface at the top with three interfaces under it: List (grows, keeps order) with ArrayList and LinkedList, Set (no repeats) with HashSet and TreeSet, and Queue (oldest first) with ArrayDeque and PriorityQueue. Map (key to value) stands beside the family, not under Collection, with HashMap and TreeMap. All are in java.util. Collection Listgrows, keeps order Setno repeats Queueoldest first Mapkey to value ArrayListLinkedList HashSetTreeSet ArrayDequePriorityQueue HashMapTreeMap not under Collection
Interfaces (dashed) on top, the classes you create with new below them. All live in java.util.

Collection is an interface, and under it are three more: List, Set and Queue. Map is a data structure too, but it isn't a Collection, so it stands on its own beside the family. Each has its own job: a list grows and keeps order, a set doesn't allow repeats, a queue usually serves the oldest item first, and a map stores a key and a value. PriorityQueue is the exception among queues: it picks by priority, not by who came first. Don't worry about the details yet; each gets its own lesson.

Same idea, four behaviours

List<String> orders = new ArrayList<>();      // keeps order
orders.add("Pizza");
orders.add("Tea");
orders.add("Pizza");
System.out.println("List:  " + orders);

Set<String> tags = new HashSet<>();           // no repeats
tags.add("java");
tags.add("java");
System.out.println("Set:   " + tags);

Queue<String> line = new ArrayDeque<>();      // oldest first
line.add("Asha");
line.add("Ravi");
System.out.println("Queue: next is " + line.poll());

Map<String, Integer> marks = new HashMap<>(); // key -> value
marks.put("Asha", 91);
System.out.println("Map:   Asha scored " + marks.get("Asha"));
List:  [Pizza, Tea, Pizza]
Set:   [java]
Queue: next is Asha
Map:   Asha scored 91

The list keeps every item, so Pizza appears twice. The set turns the second "java" away, which makes it good for unique values. The queue's poll takes out whoever joined first, Asha, and Ravi stays in line. The map pairs the key Asha with the value 91, and get("Asha") goes straight to it, the way a student ID would. Keep everything, drop repeats, serve the oldest, or look up by key.

Code to the interface

package org.studyeasy.s04l01;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class Ex04_InterfaceType {
    static void printRoll(List<String> names) {    // any List works
        System.out.println(names.size() + " on the roll: " + names);
    }

    public static void main(String[] args) {
        List<String> morning = new ArrayList<>();
        morning.add("Asha");
        morning.add("Ravi");

        List<String> evening = new LinkedList<>();
        evening.add("Meera");

        printRoll(morning);
        printRoll(evening);
    }
}
2 on the roll: [Asha, Ravi]
1 on the roll: [Meera]

The interface is on the left, the class on the right: List<String> morning = new ArrayList<>(). printRoll only asks for a List, so it takes an ArrayList and a LinkedList alike. It doesn't care which class built the list. That's the same idea as programming to an interface.

Recap

TypeBehaviourClasses you create
Listkeeps every item, in orderArrayList, LinkedList
Setdrops repeatsHashSet, TreeSet
Queueserves the oldest (PriorityQueue: by priority)ArrayDeque, PriorityQueue
Maplooks up a value by key; not a CollectionHashMap, TreeMap

Declare with the interface, then new the class that fits. First up: ArrayList, after a short stop at wrapper classes, which explain why it's Integer and not int in the map above.

Keep going in Java · 46 of 79

Previous
Java equals and hashCode: Why a HashSet Needs Both
Next post
Java Wrapper Classes and Autoboxing
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Related posts

Java equals and hashCode: Why a HashSet Needs Both

== asks if it's the very same object, equals compares values, and hashCode puts equal objects in the same HashSet bucket. Three small programs show what breaks when hashCode is missing.

Java Wrapper Classes and Autoboxing

List<int> won't compile because a list holds objects only. Integer.valueOf puts 87 in a box and intValue takes it out, and add and get do it for you. Then two traps: 128 == 128 is false, and unboxing a null Integer throws a NullPointerException.

Java ArrayList: The Stretchy Array

add, add at an index, get, set, remove and contains on a list of courses and a cart, why Git at index 1 pushes SQL and Spring right, removing scores below 50 with an Iterator or removeIf, List.of that can't change, and the array inside that grows from 10 to 15.

Java LinkedList vs ArrayList: Nodes or an Array

An ArrayList is one block of cells; a LinkedList is a chain of nodes with next and prev links. Orders ORD-101 to ORD-106 show addFirst, getLast, removeFirst and remove(1), why get(2) walks two hops, and why a front insert moves three values in one and changes two links in the other.

On this page

  • An array cannot grow
  • A list just grows
  • The family: Collection, and Map beside it
  • Same idea, four behaviours
  • Code to the interface
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE

Java 25, JSP, Hibernate, Spring Boot 4, REST APIs, React and Spring AI.View on Udemy ↗: FULL STACK JAVA : JAVA + JSP + SPRING BOOT AI + REACT + VIBE (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact us
Legal
Terms of UsePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.