I am trying to convert List [c, o, m, m, o, n]
to Map {0=c, 1=o, 2=m,3=m,4=o, 5=n}
using java streams
map key is index of value
List<String> list = Arrays.asList("c", "o", "m", "m", "o", "n");
Map<Integer, String> charMap = list.stream().collect(Collectors.toMap(i -> list.indexOf(i), elem -> elem, (a, b) -> a, HashMap::new));
but getting actual output as {0=c, 1=o, 2=m, 5=n} instead of {0=c, 1=o, 2=m,3=m,4=o, 5=n}. please suggest the logic