I have a class
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;
}
}
And another class that gets data from a file and returns a 2d Object array
private Object[][] getDataFromFile(String fileName) {
return dataLoader.getTableArray(fileLocation, dataSheetName);
}
//will return something like
europe, uk, london
europe, france, paris
How can I create objects of SimpleData when looping through the 2d array and adding the objects to a list so that each object of SimpleData represents a row of data?
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;
}