Collections, Streams, and Exceptions in Java

Collections, Streams, and Exceptions is an intermediate-level course of 5 lessons (about 2 h 29 min), with 15 exercises and 15 quiz questions. Prerequisites: Object-Oriented Java. Exercises are run and checked in a server-side sandbox.

  • Java
  • Intermediate
  • 5 lessons
  • 2 h 29 min
  • 15 exercises
  • Exercises run in a server sandbox

The course in brief

This course teaches you to use the Java Collections framework (List, Set, Map), to write expressive data processing with lambdas and the Stream API, and to handle errors robustly with exceptions. Each concept is practiced on concrete cases: product catalog, sales, bank accounts. It is the essential foundation before testing, Spring Boot, and JPA.

What you will be able to do

  • Choose and use the right collection (List, Set, Map) and the right implementation for your needs
  • Write lambdas, method references, and multi-criteria comparators
  • Build stream pipelines with filter, map, sorted, groupingBy, and joining
  • Use Optional to represent the absence of a result without null
  • Handle errors with try/catch/finally, business exceptions, and try-with-resources

Syllabus: 5 lessons

    • Create and manipulate a List<T> with ArrayList
    • Distinguish a mutable list from an immutable list (List.of)
    • Iterate over and filter a list without triggering a ConcurrentModificationException

    Collections frameworkList and ArrayListGeneric types

  1. 02

    Sets and Dictionaries: Set and Map

    18 min
    • Use a Set to eliminate duplicates and test membership
    • Use a Map to associate keys with values and count occurrences
    • Choose between Hash, Linked, and Tree implementations depending on the desired order

    Set (HashSet, TreeSet)Map (HashMap, TreeMap)equals and hashCode

  2. 03

    Lambdas, Comparator, and Your First Streams

    18 min
    • Write lambdas and method references
    • Sort objects with Comparator.comparing, reversed, and thenComparing
    • Build a filter / map / sorted / toList stream pipeline

    Lambdas and functional interfacesComparatorStreams

  3. 04

    Collectors, Grouping, and Optional

    18 min
    • Group and aggregate with Collectors.groupingBy, counting, summingInt
    • Produce strings with Collectors.joining
    • Work with an Optional without risking a NoSuchElementException

    CollectorsOptionalReduction

  4. 05

    Handling Errors with Exceptions

    20 min
    • Catch and handle exceptions with try / catch / finally
    • Distinguish checked from unchecked exceptions
    • Create your own business exceptions and release resources with try-with-resources

    Exceptionstry-with-resourcesCustom exceptions

Final project

E-Commerce Order Analyzer

Write a Java program that reads an order export in text format (one order per line: id;client;categorie;montant;statut). The program must skip and report invalid lines using exceptions, then produce a report: sorted revenue by category, number of orders per status, top 3 customers by cumulative amount, and an order lookup by identifier that returns an Optional.

Deliverables

  • A complete Main.java file (Commande records, ImportException exception, RapportCommandes class)
  • A sample dataset of at least 15 lines, 3 of which are invalid
  • The report output for this dataset
  • A short text explaining the choice of collections and collectors used

Assessment criteria

  • Invalid lines are reported with their line number without interrupting processing
  • Aggregations use groupingBy and appropriate downstream collectors, with a deterministic display order
  • No call to Optional.get() without checking, no empty catch
  • The code is readable: records, short methods, explicit names
  • The report results are correct for the dataset provided

Frequently asked questions

Do I need to know object-oriented programming before this course?

Yes: the course assumes you can write classes, records, and simple interfaces, as covered in the object-oriented Java course.

Which Java version is used?

Java 25, the current LTS release. The examples use records, sequenced collections (getFirst, getLast, reversed), Stream.toList(), modern switch, and the unnamed variable _ in catch blocks.

Do streams replace for loops?

No. Streams are more readable for chaining filtering, transformation, and aggregation, but a loop is sometimes clearer. The course teaches you how to choose.

Does this course prepare me for Spring Boot?

Yes. Collections, streams, Optional, and business exceptions are used constantly in the Spring Boot services and controllers covered later in the track.

This course, told for your job

Say what you want to be able to do: “Collections, Streams, and Exceptions” takes its place in your path, with examples from your field. The concepts stay those of the course.

The preview is free, and you can take the courses one at a time without paying. The path only contains lessons from the catalogue.