I have a list of natural numbers. How can I subgroup all the numbers divisible by 3, 5 and both, using Java Stream API?
For example:
ArrayList<Integer> list = new ArrayList<>();
list.add(24);
list.add(25);
list.add(45);
list.add(30);
list.add(3);
list.add(20);
list.add(5);
I want l3 = [3,24] , l5 = [5,20,25], l35 = [45,30]
Also, I don't want to call groupingBy()
three times on the list as the list is really huge.