我有一堂课
public class SimpleData() {
String continent;
String country;
String city;
public SimpleData(String continent, String country, String city) {
this.continent = continent;
this.country = country;
this.city = city;
}
}
另一个从文件中获取数据并返回二维对象数组的类
private Object[][] getDataFromFile(String fileName) {
return dataLoader.getTableArray(fileLocation, dataSheetName);
}
//will return something like
europe, uk, london
europe, france, paris
如何在循环二维数组并将对象添加到列表时创建 SimpleData 对象,以便 SimpleData 的每个对象代表一行数据?
private List<SimpleData> getDataList() {
Object[][] array = readDataFromFile("myfile");
List<SimpleData> dataList = new ArrayList<SimpleData>();
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
//what's the code to generate object with the correct row of data?
}
}
return dataList;
}