按页面行顺序对Points的ArrayList进行排序

时间:2017-08-23 06:29:33

标签: java sorting points

我需要按页面行顺序订购Points的ArrayList。假设这些点为text的Rectangle的minX和minY。

说我有点如下

点(100,10),点(110,20),点(125,5),点(130,10)

排序顺序应与页面行项目对齐

即Point(125,5),Point(100,10),Point(130,10),Point(110,20)

我试图先按Y坐标对X进行排序,然后按X坐标

进行排序
public int compare(final Point a, final Point b) {
    if (a.y() < b.y()) {
        return -1;
    }else if (a.y() > b.y()) {
        return 1;
    }else {
        return 0;
    }
}

public int compare(final Point a, final Point b) {
    if (a.x() < b.x()) {
        return -1;
    }else if (a.x() > b.x()) {
        return 1;
    }else {
        return 0;
    }
}

enter image description here

以下是我现在的订单

Line = 0.00 2450 00 SewiceTax @ 14 on,Sub Total Two Thousand Four Fifty only INR

Line = Swachh Bharat Cass @ O 50 42&#39;:

Line = Knshu Kaiyan Cass @ 0'50“5

行=减少提前支付

行= 2450 GD应付余额

预计是

线=子总计两千四百五十二只24 2450 00INR SewiceTax @ 14 on,

2 个答案:

答案 0 :(得分:0)

使用Comparator,并根据您的用例覆盖compare()。 这些链接将帮助您

How to sort ArrayList using Comparator?

How to use Comparator in Java to sort

答案 1 :(得分:0)

这对你有用。先按Y坐标对点进行排序,然后按X坐标排序。

1) open instagram 

2) goto settings page

3) switch permission 

4)return to app