16, java set 转list方法
2019-01-10 本文已影响0人
滔滔逐浪
Map<String, String> map = new HashMap<String, String>();
map.put("ele1", "小樱");
map.put("ele2", "若曦");
map.put("ele3", "晴川");
Set<String> set = map.keySet();
1. 通过ArrayList进行转换
List<String> list1 = new ArrayList<String>(set);
for(int i = 0; i < list1.size(); i++){
System.out.println("list1(" + i + ") --> " + list1.get(i));
}
2. List实现类进行转换
List<String> list2 = new ArrayList<String> ();
list2.addAll(set);
for(String elem : list2){
System.out.println(elem);
}