This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi all, I am learning collections and trying to implement a simple application. I have 20 different String objects and i want to select one of them randomly when i click a button. None of them should be selected twice. Which collection class is the best? How should i construct the programlogic? Thanks in advance for any suggestions. Cheers
There are lots of ways you could do this, including a clever algorithm using a simple array. But if you're using Collections, you might consider the trade off between fast lookup (for selecting elements) and fast deletions from the middle (if you decide to remove elements as they're selected).
What ideas have you considered so far?
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
i thought so: generate a number with Math.random() and use map to store strings with numbers. get the string with corresponding number. But i don't want to get the same string again when random() the same number returns. putting it in a loop until it returns a different number? How can i check it? Arraylist and Collections.shuffle() sounds good but does it solve the repetition problem? thanks alot again for the answers Cheers