Java: How to sort custom type ArrayList

前端 未结 4 1862
时光取名叫无心
时光取名叫无心 2021-01-14 04:57

I have a custom type Position(x,y,z),now I create a ArrayList, i want to sort this array ordered by the value of z, from small to b

4条回答
  •  灰色年华
    2021-01-14 05:11

    try

    Collections.sort(SortList, new Comparator(){
                public int compare(Position p1, Position p2) {
                    return p1.z- p2.z;
                }
            });
    

提交回复
热议问题