Skip to content
Advertisement

Select Random element from ArrayList print then remove It

JavaScript

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?

Advertisement

Answer

Fast and simple, make use of Collections.shuffle

JavaScript

First run…

JavaScript

Second run…

JavaScript

Obviously, each run will give different results

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement