ArrayList<String> question = new ArrayList<String>();
Scanner scan = new Scanner(System.in);
for (int i=0;i<userQuestionList.size();i++){ //get questions
if (i%2 == 0){
question.add(userQuestionList.get(i));
}
}
for (int j = 0; j < question.size(); j++) { // get ans
Random ran = new Random();
System.out.print(question.remove((ran.nextInt(question.size()+1)))+" ");
String ans = scan.nextLine();
answer.add(ans);
}
}
Hi so I have this array list of questions and I want to choose it randomly then delete it one by one until there's no more so that It wont load the same question twice but there is some problem for example I have 3 questions in the question arraylist sometime it only loads 1 or two even the same question then throw me out of bound can anyone help?
rnd.nextInt(question.size()).rnd.nextInt(3)will randomly return 0, 1, or 2. Which matches exactly the sensible values to pass to theremove()method of an arraylist with 3 elements in there. "If it only loads 2", you have further problems.