2017-06-18 90 views
-5

我有一个输入hashtable中的一些值的问题, HashMap<String, ArrayList<Integer>>必须包含名称和相对points.I'm无法为键更多的值。 输入文件如下。#java HashMap和输入

Marco,Matteo,Luca,Giovanni;34,35,3,35 
Marco,Anna,Chiara;1,5,6 
+4

而你的问题是... –

+0

你是什么意思的“相对点”? – alejandrogiron

+0

只需使用一个'HashMap ' – victor

回答

1

地图不接受重复密钥。

你可以切换到使用一个地图的列表(每行一个地图):

List<Map<String, Integer>> records = ... 
Map<String, Integer> map1 = new HashMap<>(), 
    map2 = new HashMap<>(); 
map1.put("Marco", 34); 
map1.put("Matteo",35); 
//put values for Luca,Giovanni... 
records.add(map1); 
//create and add maps for other rows 

或映射一个列表/阵列(每列一个清单)

Map<String, List<Integer>> map1 = new HashMap<>() 
List<Integer> marco = ... 
marco.add(34); 
marco.add(1); 
map1.put("Marco", marco); 
//do the same for other records... 
+0

在什么情况下,地图列表比地图列表更有意义? – victor

+0

不幸的是,该程序必须能够读取具有该结构的每个文件。我写了这段代码,但我不知道如何写最后一部分它不订阅密钥 –

+0

{String [] name = line.split(“;”)[0] .split(“,”); \t \t \t \t \t ArrayList p = new ArrayList (); \t \t \t \t \t对(INT I = 0; I st = new ArrayList (); \t \t \t \t \t对(INT I = 0; I (); \t \t \t \t \t \t \t \t st.add(p.get(I)); \t \t \t \t \t \t \t \t h.put(名称[I],ST); \t \t \t \t \t \t \t} –