Java · Intermediate level

Intermediate level · Module 2 of 6 · 16 guided hours

The Java Collections Framework

Use List, Set and Map effectively, sort data with Comparable and Comparator, and understand equals and hashCode.

Learning objectives

  • Choose the right collection for a task
  • Sort and search collections with Comparable and Comparator
  • Implement equals and hashCode correctly for objects used in sets and maps

Topics

  • List, Set, Map and Queue interfaces
  • ArrayList, HashSet, HashMap, TreeMap
  • Comparable and Comparator
  • equals and hashCode
  • Iterator and safe removal
  • Collections utility methods

Lessons

  1. Lesson 1 Lists, Sets and Maps

    Compare the main collection types and choose between them based on ordering, duplicates and lookup needs.

    ListSetMapHashMap.merge / getOrDefault

  2. Lesson 2 Sorting with Comparable and Comparator

    Give classes a natural order with Comparable and sort in any other order with Comparator chains.

    Comparable.compareToComparator.comparingthenComparingreversed

  3. Lesson 3 equals, hashCode and Safe Iteration

    Make your own objects work correctly as Set elements and Map keys, and remove items safely while iterating.

    equals contracthashCodeConcurrentModificationExceptionIterator.remove

Practical activity

Analyse a market price list: remove duplicate products with a Set, group prices by product with a Map and print products sorted by price and name.

Expected outcomes

  • Correct collection choices justified by the task
  • Reliable sorting and grouping of data

Assessment

Written and practical quiz: choose a collection for five scenarios and implement a Comparator for multi-field sorting.

Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.