Sort list of lists
in
Programming Questions
•
11 months ago
Hi guys
I have a list of x number of lists compound by 2 elements: a class and a distance. I want to sort these lists regarding the distance. As far as I know, sort() only affects a list of individual variables, not lists. Besides that I have no clue what to try now.
The list that contains all the others is the one called "allData". The "eachFood" arraylists are inside the former.
Any advice is welcome! Thanks in advance
I have a list of x number of lists compound by 2 elements: a class and a distance. I want to sort these lists regarding the distance. As far as I know, sort() only affects a list of individual variables, not lists. Besides that I have no clue what to try now.
The list that contains all the others is the one called "allData". The "eachFood" arraylists are inside the former.
Any advice is welcome! Thanks in advance
- void sortFood(){
- ArrayList allData = new ArrayList();
- for (int i = 0; i<food.size(); i++){
- ArrayList eachFood = new ArrayList();
- Food tempFoodNeigh = (Food) food.get(i);
- eachFood.add(tempFoodNeigh);
- PVector tempFoodCoords = tempFoodNeigh.returnLocation();
- float sortDist = dist(location.x, location.y, tempFoodCoords.x, tempFoodCoords.y);
- eachFood.add(sortDist);
- allData.add(eachFood);
- }
- //SORT DIST AND REDO FOOD LIST
- sort(allData)
- }
1