title: Using HashSet to store a text file and read from it
body: <p>I've seen a lot of great resources regarding HasSets, but nothing that helps me with this particular problem. I'm taking an algorithms class on generics and this assignment requires a txt file to be read into the system using Scanner (which is done) and using a hashSet, load the txt file so that I can read it with user input and find the number of occurrences of the word. i have the method for returning words and I have most of the hashSet and file reader code done. But I'm completely stuck on how to store the whole txt file as one hashSet. i couldn't get it to work by doing crime.add and i tried several other things. Am I missing an easier way to implement this method?  Thanks</p>
  
  <p>Edit: assignment instructions - 
  Program 1 (70 points)
  Load a java.util.HashSet with the the words from the novel “Crime and Punishment”, by
  Theodore Dostoevsky (text file available on Blackboard with this assignment). Prompt the user to
  enter a word and report whether or not that word appears in the novel.</p>
  
  <p>Edit: Ok, I have all of this written and it runs but it is not finding words that are definitely in the txt file, so somewhere I went wrong adding the file into the hashSet. Any ideas? I've tried with array list, different String implementations and I just don't know where to turn. Thanks for any helpful info.</p>
  
  <pre><code>import java.awt.List;
  import java.io.File;
  import java.io.FileNotFoundException;
  import java.util.HashSet;
  import java.util.Scanner;
  import java.util.Set;
  
  public class CandPHashSet {
      public static void main(String[] args) throws FileNotFoundException{
          Scanner file = new Scanner(new File("crime_and_punishment.txt")).useDelimiter("[ˆa-zA-Z]+");
          Scanner input = new Scanner(System.in);
  
          Set&lt;String&gt; crime = new HashSet&lt;String&gt;();
  
          while(file.hasNext()){
              String line = file.nextLine();
              //String[] words = line.split("[ˆa-zA-Z]+");
              for (String word : line.split("[ˆa-zA-Z]+")){
                  crime.add(line);
              }
          }
  
          String search;
          System.out.println("Enter a word to search for: ");
          search = input.next();
  
          if(crime.contains(input)){
              System.out.println("Yes");
          }else{
              System.out.println("No");
          }
      }
  }
  </code></pre>