不多废话,直接看代码,有注解
public class Map转List {
public static void main(String[] args) {
//开辟空间
HashMap<Integer,String> hashMap = new HashMap<Integer,String>();
//存入数据
hashMap.put(1,"张三");
hashMap.put(2,"李四");
hashMap.put(3,"王五");
//使用Collection类型接收HashMap的Value值
Collection<String> collection = hashMap.values();
//把Collection对象作为参数传入ArrayList构造方法完成类型转换
ArrayList<String> arrayList = new ArrayList<String>(collection);
//输出测试
System.out.println(arrayList.toString());
}
}