I am currently using the following code:
Map<Integer, Integer> numbersMap = new HashMap<>();
return IntStream.generate(() -> (int)(10 * Math.random() + 1)).filter(i -> numbersMap.put(i, i) == null).limit(3).toArray();
For example, I am wondering if there is a way to do this without the use of a HashMap, since I am only using the keys.
Aucun commentaire:
Enregistrer un commentaire