You need to enumerate through all the items in a collection, but you don’t want to visit items in order.
Create the RandomIterator class shown below, and use it to store an ArrayList of randomly ordered items.
By default, enumeration moves through the items of a collection in order from first to last. And while it’s easy to randomly select a single item in a collection using the Random class, it’s more difficult to randomly walk through all items in a collection and ensure that each one is visited only once.
The solution is the RandomIterator class shown below. It stores a private collection and inserts all items into that collection in a random order. You can then walk through ...