I am learning to do thing using Java8 and Stream. I have a problem which I am trying to solve using java8 stream.
I have a Map with type Map<String, List<Integer>> accountMap
Data - {0000132861=[6613, 6170, 6206], 0000135932=[6613, 6170, 6206], 0000122989=[6613, 6170, 6206], 0000138372=[3187, 6613, 8167, 6170, 6206], 0000138399=[6613, 6170, 6206]}
I want all the unique integer values inside the Map.value().
Like [3187, 6613, 8167, 6170, 6206]
When I do accountMap.values()
I get List<List<Integer>>
[[6613, 6170, 6206], [6613, 6170, 6206], [6613, 6170, 6206], [3187, 6613, 8167, 6170, 6206], [6613, 6170, 6206]]
When I do accountUserMap.values().stream().collect(Collectors.toSet())
I get same data type Set<List<Integer>> [[3187, 6613, 8167, 6170, 6206], [6613, 6170, 6206]]
But all the duplicate list are dropped.
I want to drop all the duplicate values and want to get Set<Integer> [3187, 6613, 8167, 6170, 6206]
There should be an efficient way to do it without using .forEach() or iterating the list.