java - Sort ArrayList by double values -
i have arraylist double values:
double distance = haversinealgorithm.haversineinkm(lat, lon, stop.getstoplat(), stop.getstoplon()); distancelist.add(distance);
i can smallest value in list this:
int minindex = distancelist.indexof(collections.min(distancelist)); currentlist.get(minindex); //it smallest value element
but have know second smallest value , third smallest value element too. don't know how.
i tried sort list this:
collections.sort(distancelist);
but it's not working. mean last index of list isn't smallest or highest value.
is here can explain me how can solve ? :)
this code looks good:
int minindex = distancelist.indexof(collections.min(distancelist)); currentlist.get(minindex); //it smallest value element
so since in sorted order, can smallest, 2nd smallest, , 3rd smallert value bying directly calling index.
currentlist.get(0); currentlist.get(1); currentlist.get(2);
Comments
Post a Comment