I\'ve got two arrays of question and answers
String questions[] = {
\"Q1?\",
\"Q2?\",
\"Q3?\"};
String answers[] = {
\"A1?\",
\"A2?\",
\"A3?\"}
You can rather shuffle a new array which holds the indices. And then get the elements from both array from the first index.
List indexArray = Arrays.asList(0, 1, 2);
Collections.shuffle(indexArray);
String question = questions[indexArray.get(0)];
String answer = answers[indexArray.get(0)];
Of course, creating a class
containing questions
and answers
would be a more OO way, as other answers suggest. That way, you would have to maintain just one List
or array
, as compared to 3 arrays
in the current approach.