如何把map的value转为list_Java 8 将Map转换为List
将一个Java示例转换Map为List
汇总:
Map map = new HashMap<>();
// Convert all Map keys to a List
List result = new ArrayList(map.keySet());
// Convert all Map values to a List
List result2 = new ArrayList(map.values());
// Java 8, Convert all Map keys to a List
List result3 = map.keySet().stream()
.collect(Collectors.toList());
// Java 8, Convert all Map values to a List
List result4 = map.values().stream()
.collect(Collectors.toList());
// Java 8, seem a bit long, but you can enjoy the Stream features like filter and etc.
List result5 = map.values().stream()
.filter(x -> !"apple".equalsIgnoreCase(x))
.collect(Collectors.toList());
// Java 8, split a map into 2 List, it works!
// refer example 3 below
~~~~~~~~~~~~~~~~~~~~~~~~~~
分类:<
将一个Java示例转换Map为List 汇总: Map map = new HashMap<>(); // Convert all Map keys to a List List result = new ArrayList(map.keySet()); // Convert all Map values to a List List result2 = new ArrayList(map.values()); // Java 8, Convert all Map keys to a List List result3 = map.keySet().stream() .collect(Collectors.toList()); // Java 8, Convert all Map values to a List List result4 = map.values().stream() .collect(Collectors.toList()); // Java 8, seem a bit long, but you can enjoy the Stream features like filter and etc. List result5 = map.values().stream() .filter(x -> !"apple".equalsIgnoreCase(x)) .collect(Collectors.toList()); // Java 8, split a map into 2 List, it works! // refer example 3 below ~~~~~~~~~~~~~~~~~~~~~~~~~~ 分类:<