Here is the SQL version for the input and output :
with tab1 as (
select 1 as id from dual union all
select 1 as id from dual union all
You may do it like so,
Map countByNumber = myList.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
List uniqueNumbers = myList.stream()
.filter(n -> countByNumber.get(n) == 1)
.collect(Collectors.toList());
First create a map using the value and the number of occurences. Then iterate over the List
of numbers, get the occurences from the map
for each number. If the number of occurences is 1, then collect it into a separate container.
If you want to do it in one go, here it is.
List uniqueNumbers = myList.stream()
.collect(Collectors.collectingAndThen(Collectors.groupingBy(Function.identity(),
Collectors.counting()),
m -> myList.stream().filter(n -> m.get(n) == 1).collect(Collectors.toList())));