As Rudi Kershaw said, there isn't much to fix technically. Whatever your way of implementation is, you need to count the occurences, select the odd ones and collect the values. Streams are not inherently readable so what you can do is to concentrate on the presentation a bit more. The variable names you use are either straight out confusing or just not very descriptive.
For example, you're processing Map.Entry
objects, not Map
objects, when filtering out the odd ones. Thus use entry
in the lambda instead of map
:
.filter(entry -> entry.getValue() % 2 == 1)
Likewise when picking the keys from the entries, use a variable name that describes the object being processed:
.map(entry -> entry.getKey())
With those changes and some formatting, your code becomes this. For someone who is familiar with common stream concepts, this should be pretty clear.
List<Integer> oddOcuranceNumbers = numbers.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
.entrySet().stream()
.filter(entry -> entry.getValue() % 2 == 1)
.map(entry -> entry.getKey())
.collect(Collectors.toList());