evemzee
evemzee

Reputation: 45

A Java array with all the words in the English language? (or something with the same effect)

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

Answers (6)

user7688205
user7688205

Reputation: 11

It's an excellent question for which there are two methods:

  1. Open a dictionary, and type out every damn word!
  2. Write a program that accepts a word from the user and stores it after categorizing it, into an array.

Both methods are quite tedious, but at least with the second one, you won't have to do everything yourself :)

Upvotes: 1

James Bassett
James Bassett

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

bchetty
bchetty

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

Peter Lawrey
Peter Lawrey

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

Manish
Manish

Reputation: 3968

Having large amount of "words" in the array will be highly inefficient. But if your purpose is just experimenting, you can

  • Copy large amount of text in a text file.
  • Read the contents of that text file into a string
  • Tokenize/Split the string contents on whitespace

Upvotes: 0

nsanders
nsanders

Reputation: 12636

The Word List project on source forge has a bunch of lists you could use.

Upvotes: 0

Related Questions