this method is supposed to iterate on the TreeMaps keys. Then it should add the key to an ArrayList variable because I need to return it as one. One more thing I want to do is to sort the ArrayList.
ArrayList<String> getVehiclenames() {
ArrayList<String> vehicleList = new ArrayList<>();
for (String elem : vehicles.keySet()) {
vehicleList.add(elem);
}
Collections.sort(vehicleList);
return vehicleList;
}
I am not 100%ly sure wether thats working, but I still couldnt believe anyways that calling a collections method just sort my vehiclelist like that. I expected something like vehicleList = Collections.sort(vehicleList);.
My questions: Is this working like that? And if yes: How is that working? I tried to look it up but my knowledge is to norrow right now.