I have this simple class
public class Rule {
int id;
long cableType;
I'm want to convert list with this classes to Map<Integer, Long>
I wrote this code:
Map<Integer, Long> map = ruleList.stream().collect(Collectors.toMap(Rule::getId, Rule::getCableType));
But in this list I have the duplication like (1, 10), (1,40)
And when I'm running this code I get this exception:
Exception in thread "main" java.lang.IllegalStateException: Duplicate key 21 (attempted merging values 31 and 30)
How I can fix this?