Hi!
I am working on a sorting algorithm but I am still having some trouble. I have an array list ArrayList<ArrayList<Float>> segs = new ArrayList<ArrayList<Float>>();
and I want to sort() (width the default function) the ArrayList of Floats - segs.get(0).sort() (something like this but it doesn’t work)
import java.util.Collections; //import Collections
ArrayList<ArrayList<Float>> segs = new ArrayList<ArrayList<Float>>();//your array
//Fill your array with random float values
for(int i=0; i<100; i++){
segs.add(new ArrayList<Float>());
for(int j=0; j<100; j++)
segs.get(i).add(random(0,10));
}
printArray(segs.get(0)); //display the first row of seg
Collections.sort(segs.get(0)); //sort it by using Collections
printArray(segs.get(0)); //display the first row of seg sorted
You can achieve what you want by using the Collections class (you just give it your ArrayList and he do the job)