I have a CSV file that looks like:
我已将其读入ArrayList,并希望通过ArrayList进行索引并打印值(这些值的类型不同,例如字符串、double和int).我try 过的代码是:
public static void main(String[] args) throws IOException
{
System.out.println("Data from CSV file to be analysed:"+"\n");
String file = "jrc-covid-19-all-days-of-world_ASSIGNMENT-FIXED.csv";
ArrayList<Integer> lines = new ArrayList<Integer>();
String line = null;
try(BufferedReader bufferedReader = new BufferedReader(new FileReader(file)))
{
int i = 0;
while(((line = bufferedReader.readLine()) != null) && i<27)
{
String[] values = line.split(",");
i++;
System.out.println(Arrays.toString(values));
}
}
catch (IOException e)
{
e.printStackTrace();
}
int thirdCountry[] = lines.get(3);
int cp3 = thirdCountry[6];
System.out.println(cp3); //should return the value 107122
但我收到了错误消息:不兼容的类型:整数不能转换为int[].