java8之map与list转化

java8之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());
	//list转化成Map
	Map map1 = employeeList.stream()
				.collect(toMap(Employee::getName, Function.identity()));

你可能感兴趣的:(java)