我必须选择一个Java Collection来存储和操作表中的数据。表格结构为:Create table Team(team_id int primary key, Female int, Male int, Total int)
到目前为止,我已经使用了LinkedHashMap,我得到了这个:
LinkedHashMap<Integer,Integer> male=new LinkedHashMap<Integer,Integer>();
male.put(1,108);
male.put(2,107);
male.put(3,108);
male.put(4,108);
male.put(5,108);
male.put(6,109);
LinkedHashMap<Integer,Integer> female=new LinkedHashMap<Integer,Integer>();
female.put(1,23);
female.put(2,23);
female.put(3,23);
female.put(4,22);
female.put(5,23);
female.put(6,23);
Set maleSet = male.entrySet();
Set femaleSet=female.entrySet();
Iterator miterator = maleSet.iterator();
Iterator fIterator = femaleSet.iterator();
Map.Entry me1 = (Map.Entry)miterator.next();
Map.Entry me2 = (Map.Entry)fIterator.next();
while(miterator.hasNext()&&fIterator.hasNext()){
System.out.println(me1.getKey+"\t",me1.getValue+"\t"+me2.getValue+"\n");
}
这适合这个问题吗?我还需要在另一个LinkedHashMap集中添加值并存储。我怎么能这样做?
答案 0 :(得分:0)
你可以尝试,或重写它。
Table<R,C,V> table = HashBasedTable<R,C,V>.create()