Reputation: 45
Pretty much, I'm writing a program that will run the same code on each word in an array. I have made an array with about 50 words just to try it, and it works great. Does anyone know of a way to get all words in the English Language (or at least a fairly large amount, like the contents of a Dictionary) into a Java array?
Thanks in advance for any replies!
Upvotes: 1
Views: 10762
Reputation: 11
It's an excellent question for which there are two methods:
Both methods are quite tedious, but at least with the second one, you won't have to do everything yourself :)
Upvotes: 1
Reputation: 9868
You've said in the comments that
It's not really a problem about what the words ARE (it's not a program that writes a story for example), i just need a MASSIVE amount of words
Do they have to be words, or could you just use randomly generated combinations of letters and/or digits instead? You haven't clarified your true objective - if you just want to experiment with IO and arrays, then you don't need real data.
Upvotes: 0
Reputation: 2241
Apart from being a inefficient data structure to hold dictionary data, Arrays can hold duplicates. So, if you are adding words to the Array, are you sure you aren't adding duplicates? ..If you are checking for duplicates, that adds an other layer of code complexity, which increases the run-time/algo complexity and decreases the performance.
Upvotes: 1
Reputation: 533530
On linux you can do this. It includes a lot of "words" I am not sure is English.
BufferedReader br = new BufferedReader("/usr/share/dict/words");
Set<String> words = new LinkedHashSet();
String line;
while((line = br.readLine()) != null) words.add(line);
br.close();
Upvotes: 4
Reputation: 3968
Having large amount of "words" in the array will be highly inefficient. But if your purpose is just experimenting, you can
Upvotes: 0
Reputation: 12636
The Word List project on source forge has a bunch of lists you could use.
Upvotes: 0