title: counting number of words in linked list
body: <p>I'm trying to put a textfile into a linkedlist. I have successfully put the textfile into a linkedlist and I'm trying to count the number of specific word. My approach was to loop through the linked list and see if the exact same word is in the list. However, my console won't stop running and I can't seem to find a problem. I would very much appreciate it if someone can tell me what is wrong with my code.</p>
  <pre><code>    public String fiile_Reader() throws FileNotFoundException {
          File file = new File(&quot;/Users/djhanz/IdeaProjects/datalab2/pg174.txt&quot;); //reading a plain text file
          Scanner scan = new Scanner(file);
          String fileContent = &quot;&quot;; // initalizing an empty string to put scanned string text file
  
          while (scan.hasNextLine()) {
              fileContent = fileContent.concat(scan.nextLine() + &quot;\n&quot;); // scan and put in into string object
          }
          fileContent = fileContent.replaceAll(&quot;\\p{Punct}&quot;, &quot;&quot;); // remove all the punctuation characters
          fileContent = fileContent.toLowerCase();
          return fileContent;
      }
  </code></pre>
  <p>Above is the code that I used to read the file.</p>
  <pre><code>public void insert() throws FileNotFoundException{
          Node cursor = head;
          Single_LL Linked_L = new Single_LL();
          String file_content = Linked_L.fiile_Reader();
          String[] splitted_File = file_content.split(&quot; &quot;);
  
          for(int i=0 ; i&lt;splitted_File.length; i++){
              Linked_L.add(splitted_File[i]);
          }
      }
  </code></pre>
  <p>And this is how inserted into a linked list</p>
  <pre><code>  public int Word_Counter(String word){
          String compare =word;
          Node cursor = head;
          int counter = 0;
          while(cursor!=null){
              if (cursor.data.equals(compare)){
                  counter++;
                  cursor = cursor.next;
              }
          }
          return counter;
      }
  </code></pre>
  <p>I'm having trouble with this word_Counter function.</p>
  <p>Below is my test code</p>
  <pre><code>public static void main(String[] args) throws FileNotFoundException {
          Program1 test = new Program1();
          String file_content = test.fiile_Reader();
          Single_LL Linked_L = new Single_LL();
          String[] splitted_File = file_content.split(&quot; &quot;);
          int spli_len = splitted_File.length;
          for(int i =0; i&lt; spli_len; i++){
  
              Linked_L.add(splitted_File[i]);
          }
          int counted = Linked_L.Word_Counter(&quot;persian&quot;);
          System.out.println(counted);
  </code></pre>
  <p>How can I count the number of words in the list??</p>