Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

java list comparator lambda

List<Target> list = new List<>();
list.sort(Comparator.comparingInt(target -> distanceTo(target.getPosition())));

public int distanceTo(Point position) {
    int distance = 0;
    distance += Math.abs(position.x - this.getPosition().x);
    distance += Math.abs(position.y - this.getPosition().y);
	return distance;
}
 
PREVIOUS NEXT
Tagged: #java #list #comparator #lambda
ADD COMMENT
Topic
Name
6+4 =