Using the Comparator class in Java 8 to compare objects
November 12, 2016 1 Comment
Java 8 comes with a range of built-in implementations of the Comparator interface.
Consider the following Employee class:
public class Employee
{
private UUID id;
private String name;
private int age;
public Employee(UUID id, String name, int age)
{
this.id = id;
this.name = name;
this.age = age;
}
public UUID getId()
{
return id;
}
public void setId(UUID id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public int getAge()
{
return age;
}
public void setAge(int age)
{
this.age = age;
}
}
…and the following list of employees: