HI I have sth like this:
case 9:
vehicleList.sort(Comparator.comparingInt(Vehicle::getMileage));
// System.out.println(here);
break;
How to print result of that sorting?
HI I have sth like this:
case 9:
vehicleList.sort(Comparator.comparingInt(Vehicle::getMileage));
// System.out.println(here);
break;
How to print result of that sorting?
Depending on how you want it output, you can either output the entire list like this:
System.out.println(vehicleList);
This will call toString()
on every element of vehicleList
and display it in a single line. If you want each entry on its own line, you can put it into a loop:
for(Vehicle vehicle : vehicleList)
{
System.out.println(vehicle);
}
As mentioned by Andreas, in order to avoid getting a meaningless string of characters when you output your Vehicle
, make sure to implement a toString()
method in the class that returns a String
.