Hi all, The Stream API makes a great job to work with various collections. However some simple operations are quite hard to achieve, for example collect the result into a random order list.
The best solution I came with is: Arrays.asList("a", "b", "c", "d").stream() .collect(collectingAndThen(toList(), l -> { Collections.shuffle(l); return l;})); If Collections#shuffle would return the shuffled list, then this can be written even more elegant: Arrays.asList("a", "b", "c", "d").stream() .collect(collectingAndThen(toList(), Collections::shuffle)); Thus two questions: 1) why stream has a way to sort, but not to shuffle 2) why Collections#shuffle doesn't returns the suffld list Are there objectives to address those cases? Thanks in advance, -kofemann /** caffeinated mutations of the core personality */