I'm doing a class project and I need to sort ArrayLists of custom objects based on the values of their int attributes.
I'm currenly using something like this:
public static void Sort(ArrayList <MyObject> objectList){
for (int i = 0; i < list.size()-1; i++){
for (int j = 0; j < list.size()-1; j++){
if (objectList.get(j).getA() > objectList.get(j+1).getA()){
Collections.swap(objectList, j, j+1);
}
}
}
}
The program works well if the ArrayList has less than 10^4 elements. But if I try to sort 10^5 elements it takes several minutes, and I need to sort 10^6 elements. Any suggestions?