如何将Map转为List?分为2种情况,一种是将Map中的key转为List,一种是将Map中的value转为List
importjava.util.ArrayList;importjava.util.HashMap;importjava.util.List;importjava.util.Map;publicclassMain2Test{publicstaticvoidmain(String[]args){Map<Integer,String>map=newHashMap<>();map.put(1,"1a");map.put(2,"2b");map.put(3,"3c");map.put(3,"3d");map.put(4,"4a");List<Integer>keyList=newArrayList(map.keySet());for(Integertmp:keyList){System.out.println(tmp);}List<String>valueList=newArrayList<>(map.values());for(Stringtmp:valueList){System.out.println(tmp);}}}复制代码