Browse › Collections API and Streams API in Java

Sort Objects by Using a Comparator and a TreeSet
Part of Collections API and Streams API in Java Topic: Programming
Access
StationX Infrastructure Labs — 3 attempts per lab
🔒 Add StationX Infrastructure Labs — $149 / year · 3 attempts per lab
Already have access? Sign in.
New to this? Try a free practice lab — a scripted hacking challenge in your browser, no account needed.
What you'll do
In this lab, you will implement the java.lang.Comparable and java.lang.Comparator interfaces to define comparisons for objects in a TreeSet.
- Import a project that contains the existing classes you will need
- Modify a class to implement the Comparable interface
- Sort objects by using a TreeSet
- Create a new class that implements the Comparator interface
- Sort objects by using the new Comparator class and a TreeSet
Note: Once you begin the lab, you will not be able to pause, save, or exit and then return to your lab. Please ensure that you have set aside enough time to complete the lab before you start.
- ⏱ About 30 minutes
- Counts towards: Introduction to Java