我如何将许多 int 数组从我已经导入的 csv 转换为字符串

How would i convert many int arrays to string from my csv which i have already imported

public class Airport {

static ArrayList<Flights> allFlights = new ArrayList<Flights>(); 

public static void main(String[] args) throws ParseException 
{ 
    try 
    { 
        File myObj = new File("Flights.csv");
        Scanner myReader = new Scanner(myObj); 
        
        while (myReader.hasNextLine())
        {
            
            
            String[] data = myReader.nextLine().split(",");
            Flights flight = new Flights();
            
            flight.setDateOfFlight(data[0]);
            flight.setDepartureTime(data[1]);
            flight.setArrivalTime(data[2]);
            flight.setFlightDuration(data[3]);
            flight.setDistanceTravelled(data[4]);
            flight.setDelay(data[5]);
            flight.setDepartureAirport(data[6]);
            flight.setDepartureCity(data[7]);
            flight.setArrivalAirport(data[8]);
            flight.setArrivalCity(data[9]);
            flight.setFlightNo(data[10]);
            flight.setAirline(data[11]);
            
            
            allFlights.add(flight);
            
            
            
        }
        myReader.close();
    }
    catch (FileNotFoundException e)
    {System.out.println("File cannot be found.");
    e.printStackTrace();
    
    }
}


}

下面是错误信息。

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The method setDateOfFlight(Date) in the type Flights is not applicable for the arguments (String)
    The method setDepartureTime(Time) in the type Flights is not applicable for the arguments (String)
    The method setArrivalTime(Time) in the type Flights is not applicable for the arguments (String)
    The method setFlightDuration(Time) in the type Flights is not applicable for the arguments (String)
    The method setDistanceTravelled(double) in the type Flights is not applicable for the arguments (String)
    The method setDelay(int) in the type Flights is not applicable for the arguments (String)

    at Airport.main(Airport.java:26)

您必须解析字符串以将它们转换为适当的类型,例如将 String 转换为 Double,您可以使用 Double.valueOf()

例如:

flight.setDistanceTravelled(Double.valueOf(data[4]));

其他转换会更具挑战性,需要您了解文件中的日期格式。

通常 类 有一个 valueOf() 工厂方法可以使用。