-2

如何ArrayList<Object> points基于二维数组创建datapoints

另一个问题:如果datapoints是二维ArrayList,如何将第一列lat和第二列读入lon

public class Cluster {
    private ArrayList<VisitPoint> points;

    public Cluster(List[][] datapoints) {
        Float lat;
        Float lon;
        for (int i=0; i<datapoints.length; i++) {
            lat = datapoints[i][0];
            lon = datapoints[i][1];
            points.add(new VisitPoint(lat,lon));
        }
    }

    public ArrayList<VisitPoint> getVisitPoints() {
        return points;
    }

}
4

1 回答 1

1

你可以使用List. ArrayList这是

List<List<VisitPoint>> list = new ArrayList<List<VisitPoint>>();

前迭代 -

for (List<VisitPoint> list2 : list) {
    for (VisitPoint visitPoint : list2) {
        ...
    }
}
于 2013-03-25T17:39:34.480 回答