I got these objects in constructor.
cars.add(new Car(2016, "honda", "civic"));
cars.add(new Car(2017, "Lamborghini", "aventador"));
cars.add(new Car(2000, null, "caravan"));
cars.add(new Car(2010, "dodge", null));
I need to return all the data from it in the following format: hondacivicLamborghiniaventadorcaravandodge
My function is:
public String listAllCars()
{
String result;
result = null;
if(cars == null)
{
throw new IllegalArgumentException("c cannot be null");
}
for(Car car: cars)
{
if(car.getMake() != null || car.getModel() != null)
{
result += car.getMake() + car.getModel();
}
}
return result;
}
But I end up with nullhondacivicLamborghiniaventadornullcaravandodgenull
instead of hondacivicLamborghiniaventadorcaravandodge
.