📜  java 列表比较器 lambda - Java 代码示例

📅  最后修改于: 2022-03-11 14:52:39.383000             🧑  作者: Mango

代码示例1
List 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;
}