Hi mate,
I am doing a mini program in java that let us look up word as a dictionary.
I tended to use database to store words and their meanings, but my teacher suggested me using file (or xml).
I chose using file (write a vector to file).
Can u tell me how to read my file if its size is large, and how to organize this file that best for searching!
Thanks for any help and idea!

Its unlikely you'll really need to worry about file size when you're dealig with a small dictionary, as you can get about 250 printed pages in a single MB of text, so a small dictionary shouldn't be a huge problem. That being said, if you really want it to load quickly, you could try using a HashMap and the serialize feature, which turns a java object in to a string representation or back again; then save that serized form to a file, so when you load it back, you don't have to worry about re-creating the whole object again.

If, however, you were going to use a file, you could alphabetize it, something like this:

aardvark - a small animal
ball - a spherical object
cat - the lord of the internet
droid - not the one you're looking for
diplodocus - a dinosaur

Then have your program find the file size, jump to the middle, check which word is there, if your word is higher, jump to 3/4, then test higher or lower again, thus finding the word in the minimum number of steps.

Thank you joehns22!
When i update new words to dictionary, what should i do (to esure that new words don't break the alphabet order?
If you were i, what would u do to index words in file that easy to look up(search). Ah, note that one word has these properties : word, pronunciation,wordtype (like noun, verb...), meaning.

If you're updating the dictionary through the program, when a user inserts new words, you can have the program re-sort the list and output the whole file again, or what might be easier is using a Map that auto-sorts. When reading the file you could break it up in to a String[] [word, pronunciation, wordtype, meaning] and store it in the Map with the key being the word.

Do you agree with me that i will store words in 27 file(26 letters and 1 file store words start with 0-9)

That could work, but it might be easier just to store all the words in one file, and sort them when you read it in to java.

This article has been dead for over six months. Start a new discussion instead.