I’ve got two arrays of question and answers
String questions[] = {
"Q1?",
"Q2?",
"Q3?"};
String answers[] = {
"A1?",
"A2?",
"A3?"};
I used Collections.shuffle(Arrays.asList(questions); to shuffle each arrays. How do I shuffle each array so that after shuffling they maintain same order?
You can rather shuffle a new array which holds the indices. And then get the elements from both array from the first index.
Of course, creating a
classcontainingquestionsandanswerswould be a more OO way, as other answers suggest. That way, you would have to maintain just oneListorarray, as compared to3 arraysin the current approach.