我创建一个Map从List如下:
List<String> strings = Arrays.asList("a", "bb", "ccc");
Map<String, Integer> map = strings.stream()
.collect(Collectors.toMap(Function.identity(), String::length));
Run Code Online (Sandbox Code Playgroud)
我希望保持与之相同的迭代顺序List.如何创建LinkedHashMap使用Collectors.toMap()方法?
我需要按类型将数据列表分成不同的列表,为此我使用构造
Map<String,List<Dish>> dishMap = menu.stream()
.collect(Collectors.groupingBy(Dish::getType));
Run Code Online (Sandbox Code Playgroud)
但是如何从方法"Collectors.groupingBy"获取LinkedHashMap而不是HashMap.我在javadoc中找到了一些数据但是我不能得到我必须用这个方法做的事情:
Map<String,List<Dish>> dishMap = menu.stream().collect(Collectors.groupingBy(
Dish::getType,
LinkedHashMap::new, ????));
Run Code Online (Sandbox Code Playgroud)
我应该在方法"groupingBy"的第三个参数中放置什么才能得到我需要的东西?