Reading CSV file by index Java
I have a CSV file with several columns. I have a two 开发者_JAVA百科dimensional array with 20 rows and 2 columns where column 1 is a y axis and column 2 is x axis.
I want to index through several x axis with keeping column 1 as constant.
Meaning if I have column A, B, C , D, etc then column A will be constant but I need to index through column B, C, D, etc against each row.
Using a multidimensional array might not be your best bet. I would consider a Map where the key is the column name and the value is an object array or a list.
Something like...
final int numberOfRows = 20;
Map<String, Object[]> table = new LinkedHashMap();
table.put("columnA", new Object[numberOfRows]);
table.put("columnB", new Object[numberOfRows]);
table.put("columnC", new Object[numberOfRows]);
table.get("columnA")[0] = "column A row 1";
table.get("columnA")[1] = "column A row 2";
or with a list...
final int numberOfRows = 20;
Map<String, List> table = new LinkedHashMap();
table.put("columnA", new ArrayList(numberOfRows));
table.put("columnB", new ArrayList(numberOfRows));
table.put("columnC", new ArrayList(numberOfRows));
table.get("columnA").add(0, "column A row 1");
table.get("columnA").add(1, "column A row 2");
精彩评论