我有一个输入hashtable中的一些值的问题, HashMap<String, ArrayList<Integer>>
必须包含名称和相对points.I'm无法为键更多的值。 输入文件如下。#java HashMap和输入
Marco,Matteo,Luca,Giovanni;34,35,3,35
Marco,Anna,Chiara;1,5,6
我有一个输入hashtable中的一些值的问题, HashMap<String, ArrayList<Integer>>
必须包含名称和相对points.I'm无法为键更多的值。 输入文件如下。#java HashMap和输入
Marco,Matteo,Luca,Giovanni;34,35,3,35
Marco,Anna,Chiara;1,5,6
地图不接受重复密钥。
你可以切换到使用一个地图的列表(每行一个地图):
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...
在什么情况下,地图列表比地图列表更有意义? – victor
不幸的是,该程序必须能够读取具有该结构的每个文件。我写了这段代码,但我不知道如何写最后一部分它不订阅密钥 –
{String [] name = line.split(“;”)[0] .split(“,”); \t \t \t \t \t ArrayList
可能提供你想要实现的更多细节。 据我所知,你想存储多个值的密钥?
Multimap在这种情况下很有用。 https://google.github.io/guava/releases/21.0/api/docs/com/google/common/collect/Multimap.html 希望这可以帮助你!
而你的问题是... –
你是什么意思的“相对点”? – alejandrogiron
只需使用一个'HashMap' –
victor