title: Splitting an array of strings in Java using .split
body: <p>I have browsed through questions similar to mine already on here, but have not found anything that will work for me. </p>
  
  <p>Essentially what I have to do is read a file full of strings line by line, print them line by line and then word by word. I would like to accomplish this using .split to create an array of each individual string. </p>
  
  <p>For instance, my file reads:<br>
  The fat cat was black<br>
  The cow jumped over the moon<br>
  I came to say hello world</p>
  
  <p>etc.</p>
  
  <p>I have figured out how to read the file and print the file line by line, but I cannot figure out how to print it word by word. Each of these 3 are in their own functions, so I'm not sure if that plays any role in where something is placed.</p>
  
  <p>This is what I have so far in my method:</p>
  
  <pre><code>static public void printWords( String [ ] arr, int count )
  {
      String [] s2 = arr[0].split( " " ); 
  
      for( int i = 0; i &lt; count; i++)
      {
          System.out.println(  s2 [i] );
      }
  
      System.out.println();  
  }
  </code></pre>
  
  <p>However, this is giving me an error. I switched around a couple things, but each time it prints either just the lines or stops at a certain point. The only thing I have in main is my method call pertaining to this, which is not the problem. If anyone has any insight it would be greatly appreciated. Thank you!</p>
  
  <p>EDIT:</p>
  
  <p>"Count" in my code is the number of lines in the file I am reading. So for this, it is 3.<BR><BR></p>
  
  <p>I have tweaked the code to get what I need, however it only prints the first sentence. </p>
  
  <pre><code>String [] s2 = arr[0].split( " " );
      for (int j = 0 ; j &lt; count ; j++)
      {
  
          for( int i = 3; i &lt; s2.length; i++)
          {
  
          System.out.print(  s2 [i] + " " );
          }
      System.out.println();
  
      }
  
  }
  </code></pre>
  
  <p>For example, this only prints <BR>
  The fat cat was black<BR><BR>
  And then ends. I am trying to construct another loop around it (as demonstrated by my code) but it ends up just printing "The fat cat was black" 3 times rather than moving to the next line of the file. </p>