【发布时间】:2015-09-11 03:19:27
【问题描述】:
我有一个像这样的HashMap:
Hashmap<String, Object> map = new Hashmap<String, Object>();
map.put(1, {id_student:"1;2;3"});
map.put(2, {id_student:"4;5"});
我想获取这些值并将其放入 ArrayList 中,例如:
array = [0] - 1
[1] - 2
[2] - 3
[3] - 4
[4] - 5
我想做什么:
private Set<String> checked = new TreeSet<String>();
String idsAlunos = "";
for (Iterator<Map.Entry<String, GPSEscolas>> it = aMap.entrySet().iterator(); it.hasNext(); ) {
Map.Entry<String, GPSEscolas> entry = it.next();
String id_escola = entry.getKey();
String ids_aluno = entry.getValue().getAlunos();
idsAlunos += ";" + ids_aluno;
checked.add(idsAlunos.substring(1));
}
但我从上面的代码中得到了这个结果:[4, 4;1;2;3, 4;5, 4;5;1;2;3]
【问题讨论】:
-
在android中编译吗?它不在 Java 8 中。
map.put不会采用{..}值。你是说map.put("1",new String[]{"1","2","3"});吗?
标签: java android arraylist hashmap