Let's pause before moving on to get more practice with Java's collections—the lists, maps, and sets that are so useful for solving problems. We'll also learn how we can combine these collections together to build more interesting data structures. Let's get started!
In the past lessons we've seen how to create and use several standard Java collections: List
s, Map
s, and Set
s:
These collections are quite useful on their own! However, they can also be combined to great effect. Let's see an example.
You can combine List
s, Map
s, and Set
s in many interesting ways to build data structures to solve problems.
You can create List
s of Map
s:
Or Set
s of List
s:
But generally, it's more common for the top-level data structure to be a Map
: Map
s of Map
s, Map
s of List
s, and Map
s of Sets
.
We'll get some practice working with these on this lesson's practice and homework problems.
We'll spend the rest of the lesson working on some problems that test our understanding of how to nest collections.
First, we're asked to parse a List<String>
into a Map<Set<String>>
.
Let's do an example of that together, which you can use as a starting point for the practice problem that follows.
Next let's discuss how to approach this lesson's homework problem.
This problem is a bit trickier, since we need to determine when to properly insert entries into our Map
, and do some String
parsing.
So let's discuss how to get started.
Need more practice? Head over to the practice page.