I am trying to remove duplicate numbers in java 8, including the number of links. For example, I have an array with values similar to (2,3,2,5)
All numbers 2 should be deleted, and numbers should remain 3 and 5. Thus, the expected amount is 8. However, in my code below, it still gets 2. He deleted the duplicate number, but still kept the reference to the number.
Here is my code.
List<Integer> clearedNumbers = numbers.stream().distinct().collect(Collectors.toList());
int sum = clearedNumbers.stream().mapToInt(Integer::intValue).sum();
The amount I get is 10 instead of 8.
source
share