Java:Map转List (用stream实现)

//例子
Map<Integer, String> mapDemo = new HashMap<>();
      map.put(10, "apple");
      map.put(20, "orange");
      map.put(30, "banana");
      map.put(40, "watermelon");
      map.put(50, "dragonfruit");

一、MapList

//方法1
List<Integer> list1 = new ArrayList(mapDemo.keySet());
//方法2
List<Integer> list2 = mapDemo.keySet().stream().collect(Collectors.toList());

二、MapList
//方法1
 List<String> list3 = new ArrayList(mapDemo.values());
 //方法2
 List<String> list4 = mapDemo.values().stream().collect(Collectors.toList());

你可能感兴趣的:(特殊功能实现,java,list,map)