There was a need to add 35 cars sheets (with a random number of instances) to the new listOfCars . Then do the sorting by the number of these copies.
ArrayList<Car> cars = new ArrayList<Car>(); for (int i = 0; i < a; i++) { cars.add(new Car(a)); } ArrayList <ArrayList> listsOfCars = new ArrayList<ArrayList>(); for (int i = 0; i < 35; i++) { listsOfCars.add(cars); } Collections.sort(listsOfCars, SizeComparator); System.out.println(cars); System.out.println(listsOfCars); Comparator:
public static Comparator<ArrayList> SizeComparator = new Comparator<ArrayList>() { @Override public int compare(ArrayList arrlist1, ArrayList arrlist2) { return arrlist1.size() - arrlist2.size(); } }; There is no problem in this code, since I brought him back to the look in which he works. But here I create one sheet of cars with a random number of instances, after which I add it 35 times to the listsOfCars list. But 35 different sheets with a random number of copies can not be added. Please indicate the right path.