There is an ArrayList of vehicle objects,used a number of times. Each object has an id and the number of times it was used. 

```
ArrayList<Object> usedVehicles = new ArrayList();

```

And there is another array, which keeps all the ids of vehicles.

```
int[] vehicleIDs = database.getVehicleIds();

```

I need to sort elements in **vehicleIDs** array depending on the number of times they were used, obviously the vehicles which have never been used must come first.

I think I can sort the vehicle objects in the ArrayList with comparator:

```
public class CustomComparator implements Comparator<MyObject> {
  @Override
  public int compare(Vehicle vehicle1, Vehicle vehicle1) {
     return vehicle1.getTheNumberOfTimesUsed().compareTo(vehicle2.getTheNumberOfTimesUsed()());
    }
}  

```

However, I don't know how to change the places of items in **vehicleIDs** array depending on order in the ArrayList. Additionally, the vehicles, which have never been used must come fisrt.