Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
独自の要素のセットがあります (2 つの同一の要素はありません)。そして、セットから N 個のランダムで異なる要素を抽出したいと思います。Javaでそれを行う最も簡単な方法は何ですか?
Set<MyObject> mySet = getTheSetFromSomeWhere(); List<MyObject> myObjects = new ArrayList<MyObject>(mySet); Collections.shuffle(myObjects); myObjects = myObjects.subList(0, n);