简体   繁体   中英

I am trying to create a method that converts the arrayList of vehicles to an array and returns the array

This is my code. Trying to create a method call getVehicles that will convert the arrayList of vehicles to an array and then returns the array.

public class GSM{
private ArrayList <Vehicles> vehicleList = new ArrayList <Vehicles>;
private String garageName;

public GSM (String garageName)
{
    this.garageName = garageName;
}
public void addVehicle(Vehicles A)
{
    vehicleList.add(A)
}

public Vehicles[] v getVehicles()
{

}

I am new to ArrayList and Arrays, so I am having a bit of problem with this one.

Vehicles[] arr = vehicleList.toArray(new Vehicles[0]);

请参阅此答案以获取解释: Converting 'ArrayList<String> to 'String[]' in Java

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM