Answer the question
In order to leave comments, you need to log in
How can I make random fragments in the list?
I have a list in which there will be 9 elements that should be randomly selected from the list of fragments ...
how can I do it?
Answer the question
In order to leave comments, you need to log in
List can be shuffled using Collections.shuffle
import java.util.*;
public class ShuffleDemo {
public static void main(String[] args) {
Integer[] numbers = {1, 2, 3, 4, 5, 6, 7, 8, 9};
ArrayList<Integer> numbersList = new ArrayList<>(Arrays.asList(numbers));
long seed = System.nanoTime();
Collections.shuffle(numbersList, new Random(seed));
for(int x = 0; x < numbersList.size(); x++) {
System.out.print(numbersList.get(x) + " ");
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question