的ArrayList我有一個HashMap
像這樣:如何將對象的一個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」});'? – MadConan