I would like to know how constructors with variable arguments work. Here is an example :
import java.util.ArrayList;
import java.util.List;
public class VehicleCompany {
private List<Vehicle> vehicles= new ArrayList<Vehicle>();
private void VehicleCompany (Vehicle... vehicles) {
//how to complete it?
}
Which way is the easier to do it? I found that I can copy the argumenttaxis into another list or use a for-loop but didn't how to do since this.taxis.size() is 0.
Any suggestions? Thanks!
vehicleswill be an array ofVehicleobjects (just likeVehicle[] vehicles)ArrayListwork the best for me so I can't use an arrayArrays.asList()may help.taxis? 3) What does "this.taxis.size() is 0" have to do with copying from parameter to field? The field will grown as needed. It's what anArrayListdoes.