As I was again trying to remember how to sort a list of objects in Java bases on multiple keys, I had the luminous idea to finally write it down.
We have a list of pizza’s, and I want them sorted according to size, number of toppings and furthermore by name. This means that there will be groups ordered by size and within those groups the pizza’s are ordered into groups by number of toppings and in those groups the pizza’s are ordered by name.
We want to end up with a list like this:
- Pizza’s 34cm:
- Anchovy (34cm, tomato, cheese, Anchovies)
- Prosciutto (34cm, tomato, cheese and ham)
- Chicken Special (34cm, tomato, cheese, chicken and turkey pieces)
- Vulcano (34cm, tomato, cheese, mushrooms and ham)
- Peperone (34cm, tomato, cheese, mushrooms, ham, capsicum, chili peppers and onions)
- Pizza’s 30cm:
- Anchovy (30cm, tomato, cheese, Anchovies)
- Prosciutto (30cm, tomato, cheese and ham)
- Chicken Special (30cm, tomato, cheese, chicken and turkey pieces)
- Vulcano (30cm, tomato, cheese, mushrooms and ham)
- Peperone (30cm, tomato, cheese, mushrooms, ham, capsicum, chili peppers and onions)
- Pizza’s 26cm:
- Anchovy (26cm, tomato, cheese, Anchovies)
- Prosciutto (26cm, tomato, cheese and ham)
- Chicken Special (26cm, tomato, cheese, chicken and turkey pieces)
- Vulcano (26cm, tomato, cheese, mushrooms and ham)
- Peperone (26cm, tomato, cheese, mushrooms, ham, capsicum, chili peppers and onions)