I have a List that I am trying to convert to a Map<String, String> using Java 8.
The list is as below
List<String> data = Arrays.asList("Name", "Sam", "Class", "Five", "Medium", "English")
I want a Map<String, String> such that the key value pair will be like
{{"Name", "Sam"}, {"Class", "Five"}, {"Medium", "English"}}
I am trying to achieve this in Java 8 and tried using Instream.range() but did not get the exact result.
IntStream.range(0, data.size() - 1).boxed()
.collect(Collectors.toMap(i -> data.get(i), i -> data.get(i + 1)));
The issue with the above code is the result also gives an output as {"Sam", "Class"}