在java里怎么把hashmap转换成arraylist和iterator
展开全部
import java.util.ArrayList;
import
java.util.HashMap;
import java.util.Iterator;
import
java.util.List;
import java.util.Map;
public class ConvertMapToList {
public
static void main(String[] args) {
Map map = new HashMap();
map.put("a", "a1");
map.put("b",
"b1");
map.put("c",
"c1");
List
listKey = new ArrayList();
List
listValue = new ArrayList();
Iterator it =
map.keySet().iterator();
while
(it.hasNext()) {
System.out.println(map);
String key =
it.next().toString();
listKey.add(key);
listValue.add(map.get(key));
}
System.out.println("Convert
Finished !");
//output the context of the
ArrayList
for(int i =0
;i<listKey.size();i++){
System.out.println(listKey);
System.out.print("Key
:"+listKey.get(i));
System.out.println("Value
:"+listValue.get(i));
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询