Please refer to the sample below.
jshell> List<Integer> L = IntStream.range(0, 10).filter(i -> i !=3 && i != 7).boxed().collect(Collectors.toList());
L ==> [0, 1, 2, 4, 5, 6, 8, 9]
jshell> int choiceNumber = L.get(new Random().nextInt(L.size()));
choiceNumber ==> 5
jshell> int choiceNumber = L.get(new Random().nextInt(L.size()));
choiceNumber ==> 4
jshell> int choiceNumber = L.get(new Random().nextInt(L.size()));
choiceNumber ==> 1
© 2024 OneMinuteCode. All rights reserved.