core Estimated learning time: 9 h

OE-3.4 Collections Framework & I/O

You can choose and use the right collection class, iterate and sort with comparators, store user-defined types in collections, and read and write files with stream and reader/writer classes.

The collections framework is the library you will use every single day of Java work, so learn it by the shape of the problem: ordered or not, duplicates allowed or not, keyed or not. Storing your own classes in a HashSet or HashMap only works if you have overridden equals and hashCode correctly - that omission is the classic silent bug. On the I/O side, keep byte streams and character streams distinct; mixing them is how encoding problems begin.

Work through these

  • Overview of the collection framework

    The library's answer to storing groups of things, taken as a map before the parts. Knowing the shape of the framework is what lets you choose rather than reach for the same class every time.

  • ArrayList, LinkedList, HashSet, LinkedHashSet, TreeSet

    The concrete containers, and the reason there are several: they trade insertion cost, lookup cost and ordering differently. Choosing one is a performance decision, not a style one.

  • Collection, List, Set and SortedSet interfaces

    The contracts those classes implement, which is the level you should usually write against. Programming to the interface is the habit this item exists to build.

  • Accessing a collection via an iterator; storing user-defined classes

    Walking a collection, and what your own class must provide before it can live in one. Equality and hashing are the requirements people forget, with results that look like the collection is broken.

  • Map interfaces and classes; using a comparator

    Key-value storage, and how to impose an order the type does not have on its own. Comparators are the piece that makes sorting arbitrary objects possible.

  • Legacy classes: Vector, Hashtable, the Enumeration interface

    The older classes that predate the framework, which you will meet in existing code. Know them well enough to read, and prefer the modern equivalents when writing.

  • Reading user input with the Scanner class

    Getting input from a person, which is the first thing most programs need. Small, and it is where the exception handling from the previous topic first earns its keep.

  • Stream classes: InputStream, OutputStream, FileInputStream, FileOutputStream

    Reading and writing bytes, and the layered design the library uses. The layering looks elaborate until you need to add compression or buffering, at which point it pays.

  • Reader and Writer, FileReader, FileWriter and the File class

    The character-oriented half, for text rather than bytes. Using the byte classes on text is a real bug that produces mangled output rather than an error, so the distinction matters.

Sign in to keep your progress.

Free resources

Links last checked 30 Aug 2026.

Stuck here?

Ask a mentor. A real person answers, and they can see exactly which topic you're on. Usually within a couple of working days.

Checking your session…

Topics shown in module order.