在使用流上的Collections.toMap()时,如何保持List的迭代顺序?
我正在从一个List
中创建一个Map
,代码如下:
List strings = Arrays.asList("a", "bb", "ccc");
Map map = strings.stream()
.collect(Collectors.toMap(Function.identity(), String::length));
我想保持与List
中相同的迭代顺序。我如何使用Collectors.toMap()
方法创建一个LinkedHashMap
?