Question: I am trying to build a word-based-game application in Java. I browsed through some existing questions and got some idea how to get wordlist. Some of the questions I have referred to:

[How to pick a random english word from a list](https://stackoverflow.com/questions/594273/random-word-generator)

[Random word selection](https://stackoverflow.com/questions/3689645/random-word-selection)

My motive is to generate a random word. After getting the wordlist downloaded as a text file, I am trying to generate a 

```
Map<String, Integer> m = new HashMap<String, Integer>();

```

which could give me a word since I could query it using a random integer generated.

Is this a recommended approach or is there a better way to generate a random word from the wordlist?

Thanks.

Answer: 
Stick the word list into an array or `ArrayList`, and pick a random index. `ArrayList` is easier to work with since it can grow dynamically as you're reading your dictionary file.
1. Your proposed Map does not achieve you goal, because HashMaps allow you to access a value associated with a given key, doesn't allow you to access a key associated with value. So if you use a HashMap, it should be `Map<Integer, String>`
2. The primary benefit of a HashMap over other data structures is the constant lookup time: no matter how big the map gets, the time it takes to retrieve a value for a given key stays the same. Contrast this with an unordered ArrayList where the time taken to look for an element can increase as the size of the List increases. However, since you're not looking for a specific word, just any word, the HashMap benefit doe not apply to you case.
3. As others have said, best approach seems to be:

ArrayList words = new ArrayList();

//add all the words

Random r = new Random() //Object for generating random numbers

String randomWord = words.get(r.nextInt(words.size()));