I have a file which contains data in the following format
1
2
3
I want to load this to map as {(1->1), (2->1), (3->1)}
This is the Java 8 code,
Map<Integer, Integer> map1 = Files.lines(Paths.get(inputFile))
.map(line -> line.trim())
.map(Integer::valueOf)
.collect(Collectors.toMap(x -> x, x -> 1));
I am getting the following error
Exception in thread "main" java.lang.IllegalStateException: Duplicate key 1
How do I fix this error?