What data collection can be used for rows["column"][rowIndex] in Java?
I'm trying to find a similar开发者_Go百科 or equivalent data collection used in C# DataRow class, which lets me choose the column name and row index.
Is there anything similar to this that can be used in Java?
This is somewhat similar to Etienne de Martel's answer, but I would strongly recommend using a Map of sorts. A HashMap is almost certainly he best way.
I would first make a 2D array of values, for distinguishing purposes, I'll call them Doubles:
Double[][] values = new Double[colNum][rowNum];
I would then for each column name map an integer to it:
Map <String, Integer> map = new HashMap<String, Integer>();
map.add("Column_0_Name",0);
map.add("Column_1_Name",1);
map.add("Column_2_Name",2);
map.add("Column_3_Name",3);
//...
map.add("Column_(colNum-1)_Name",colNum-1);
Then using these two together, I would create a function.
public double getValue(String columnName, int row){
int colNum = map.get(columnName);
return values[colNum][row];
}
Something that implements Map<String, List<Integer>>
would probably do what you need, such as:
Map<String, List<Integer>> data = new HashMap<String, List<Integer>>();
// ...
data.put("column", new ArrayList<Integer>());
But perhaps I misunderstood your question.
精彩评论