sort list but pass item index
in
Programming Questions
•
6 months ago
Hi guys,
I am sorting a list of distances, but I would like to know the index of the distance in order to pass the corresponding point (points[j]) instead and not the distance. Something along these lines:
ArrayList<Float> distances = new ArrayList();
ArrayList<PVector> newPts = new ArrayList<PVector>();
for(int j = 0; j < points.length; j++)
{
float d = dist(realBlobX, realBlobY, points[j].x, points[j].y);
distances.add(d);
}
//int index = distances.indexOf(distances.get(distances.size()-1));
Collections.sort(distances);
...i need to know what were the indexes of the last four elements in the sorted list so I can extract the corresponding four points.
Thanks a lot in advance,
buzz
I am sorting a list of distances, but I would like to know the index of the distance in order to pass the corresponding point (points[j]) instead and not the distance. Something along these lines:
ArrayList<Float> distances = new ArrayList();
ArrayList<PVector> newPts = new ArrayList<PVector>();
for(int j = 0; j < points.length; j++)
{
float d = dist(realBlobX, realBlobY, points[j].x, points[j].y);
distances.add(d);
}
//int index = distances.indexOf(distances.get(distances.size()-1));
Collections.sort(distances);
...i need to know what were the indexes of the last four elements in the sorted list so I can extract the corresponding four points.
Thanks a lot in advance,
buzz
1