java - Take n random elements from a List
In case you're wondering if there's a Java 8 Stream approach; no, there isn't a built-in one. There's no such thing as Comparator#randomOrder()
in standard API (yet?). You could try something like below while still satisfying the strict Comparator
contract (although the distribution is pretty terrible):
Read full article from java - Take n random elements from a List
No comments:
Post a Comment