I have written the following code:
public class NewClass2 implements Comparator
{
public int compare(Point p1, Point p2)
{
retur
I just want to expand on Peter Lawrey answer on JDK 8, if you do it like this:
public class NewClass2 implements Comparator {
public int compare(Point p1, Point p2) {
return Double.compare(p1.getY(), p2.gety());
}
}
You could define this comparator using a lambda expression pretty easily
(Point p1,Point p2) -> Double.compare(p1.getY(), p2.gety())
Better yet, you could use a member reference like this:
Double::compare