DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: java dictionary

  1. #1
    Join Date
    Nov 2005

    java dictionary

    hi guys i created a java program (element) dat looks into a file for any words a user inputs and displays any output.

    i would like to knwo how i could adavcne this tool so that the spellchcekr goes thoug the same file, and everytime it finds a word dat nt in da dictionary it can ask me to accept the wprd or enter a replace ment one.

    this is da code i done so far:

    import java.io.*;
    public class spell2
    public static void main(String[] args) throws Exception
    BufferedReader inone =new BufferedReader(new FileReader("words.txt"));
    BufferedReader in =new BufferedReader(new InputStreamReader(System.in));
    String s=in.readLine();
    while (s.length()>0)
    { String t=inone.readLine();
    while (t!=null)
    if (t.startsWith(s))
    inone =new BufferedReader(new FileReader("words.txt"));

    the file i used is a txt file full of words.

    thank u for any help

  2. #2
    Join Date
    Mar 2004
    I think your post needs a spell checker.

    Run each word in the file through the dictionary list of words. Keeping the dictionary in alphabetical order, you can use a binary search to drastically increase the speed of the word search. If the word isn't found, find the closest match (compareTo) and present the option to the user

  3. #3
    Join Date
    Mar 2006
    it appears that "words.txt" is essentially your dictionary and that you're checking works entered via the standard output. true, you could load the words in the file into a list, sort the list, and then search it later quickly using binary search. however, you could run into memory problems if "words.txt" is massive. and besides, you're interested in re-scanning the dictionary file. so, the following code should help; it is an adaptation of your code.

    Tip: When posting, you can use the # button to insert code that is laid out well with indenting so that it is easier to read.

    import java.io.*;
    public class spell2
        public static void main(String[] args)
          throws Exception
            RandomAccessFile inone = new RandomAccessFile("words.txt", "r");
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            boolean foundMatch;
            String s = in.readLine();
            while (s.length() > 0) {
                inone.seek(0L);  // return to the beginning of the dictionary
                foundMatch = false; // unless proven otherwise
                String t = inone.readLine();
                while (t != null) {
                    if (t.equalsIgnoreCase(s)) {
                        foundMatch = true;
                    t = inone.readLine();
                if (foundMatch == false) {
                    System.out.println("Unknown word: " + s);
                    // add code to keep/replace here
                s = in.readLine();

Similar Threads

  1. Replies: 2
    Last Post: 06-14-2006, 03:16 PM
  2. Java vs. .Net. A questionnaire
    By Basil in forum .NET
    Replies: 1
    Last Post: 05-13-2005, 06:46 AM
  3. DevX does seem one sideded
    By Rob Abbe in forum Talk to the Editors
    Replies: 44
    Last Post: 01-13-2003, 02:57 PM
  4. learning c# very confusing.
    By Mike Tsakiris in forum .NET
    Replies: 11
    Last Post: 10-04-2002, 05:32 PM
  5. Re: VB vs. Visual Age for Java
    By JJ in forum Enterprise
    Replies: 1
    Last Post: 07-06-2000, 04:50 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.