Comparable vs. Comparator

Comparable vs Comparator in Java

More on the Comparator Interface in Java

Lab on Comparator

Start off by creating a Laptop class to track the following variables: brand name, amount of RAM (in Gigabytes), and price in US dollars and cents. Do not add the Comparable interface to this class. Instead, in the test code, use anonymous inner classes to create three separate comparator objects: one that sorts based on brand name, one that sorts based on RAM, and one that sorts based on price.

Create 5 different laptops. Print the list before and after each sort.