java List<String[] > table 赋值 和取值问题

大家好 是这样的 能不能写成这样的形式 或者有什么方法
首先 这里设一个名字 类似这样的table.setName("xx"); 然后这里在 table.add{List<String[]>} 赋值时 要写成这样的形式 {[xx,yy],[qq,ww],[ee,rr]}
后面 取值 string a =xx ;string y =yy String name =获取table.setName("xx");的值
;string q =qq ;string r =rr ;string w =ww ;string e =ee 这样的取值 有没有什么方法啊 急求

第1个回答  推荐于2016-06-24
首先,纠正一下,List<String[] > table,这个类型为List<String[]>,名字为table,所以List<String[]>并没有setName这个方法(除非你自己重写List),至于{[xx,yy],[qq,ww],[ee,rr]} 这种赋值方式,对于List来说是不存在的(除非你自己重写List)。
如果我没有理解错你的意思的话,你是想保存一个数据表的数据
这样的话可以这样设计
编写一个类,例如:Tabel类
这个Table类包含两个属性
private String name;
private Map<String,Object[]> property;
name属性代表数据表的名字
property属性代表数据表的column以及对应数据;
这样就可以通过Table 这个类实现你所提及的赋取值
Table table = new Table();
赋值:
table.setName("my_table");
Map<String,Object[]> map = new HashMap<String,Object[]>();
map.put("r",new Object[]{"rr"});
map.put("q",new Object[]{"qq"});
......
table.setProperty(map);
取值:
String name = table.getName();
String[] r = table.getProperty().get("r");
String[] q = table.getProperty().get("q");
......
不知道有没有理解错误你的意思本回答被提问者采纳
相似回答