有没有Java8中方便的流API方法可以将List<T>
转换为Map<T, (index)>
? 就像下面的例子一样:
List<Character> charList = "ABCDE".chars().mapToObj(e->(char)e).collect(Collectors.toList());
Map<Character, Integer> map = new HashMap<>();
for (int i = 0; i < charList.size(); i++) {
map.put(charList.get(i), i);
}
map = {A=0, B=1, C=2, D=3, E=4}
zipWithIndex
操作。 - Marko TopolnikMap
的目的是什么? - Holger