title: Java Dictionary Searcher
body: <p>I am trying to implement a program that will take a users input, split that string into tokens, and then search a dictionary for the words in that string. My goal for the parsed string is to have every single token be an English word.</p>
  
  <p>For Example:</p>
  
  <pre><code>Input:
         aman
  
  Split Method:
        a man
        a m an
        a m a n
        am an
        am a n
        ama n
  
  Desired Output:
        a man
  </code></pre>
  
  <p>I currently have this code which does everything up until the desired output part:</p>
  
  <pre><code>    import java.util.Scanner;
  import java.io.*;
  
  public class Words {
  
      public static String[] dic = new String[80368];
  
      public static void split(String head, String in) {
  
          // head + " " + in is a segmentation 
          String segment = head + " " + in;
  
          // count number of dictionary words
          int count = 0;
          Scanner phraseScan = new Scanner(segment);
          while (phraseScan.hasNext()) {
              String word = phraseScan.next();
              for (int i=0; i&lt;dic.length; i++) {
                  if (word.equalsIgnoreCase(dic[i])) count++;
              }
          }
  
          System.out.println(segment + "\t" + count + " English words");
  
          // recursive calls
          for (int i=1; i&lt;in.length(); i++) {
              split(head+" "+in.substring(0,i), in.substring(i,in.length()));
          }   
      }
  
      public static void main (String[] args) throws IOException {
          Scanner scan = new Scanner(System.in);
          System.out.print("Enter a string: ");
          String input = scan.next();
          System.out.println();
  
          Scanner filescan = new Scanner(new File("src:\\dictionary.txt"));
          int wc = 0;
          while (filescan.hasNext()) {
              dic[wc] = filescan.nextLine();
              wc++;
          }
  
          System.out.println(wc + " words stored");
  
          split("", input);
  
      }
  }
  </code></pre>
  
  <p>I know there are better ways to store the dictionary (such as a binary search tree or a hash table), but I don't know how to implement those anyway.</p>
  
  <p>I am stuck on how to implement a method that would check the split string to see if every segment was a word in the dictionary.</p>
  
  <p>Any help would be great,
  Thank you</p>