title: Reading in line with blank space at end using java scanner class
body: <p>I'm helping my sisters with a simple java program and I'm stumped. They've only learned scanner classes to read file contents, so I think they're supposed to use the scanner class. Each line contains letters and potentially a blank space, and we're hoping to store each line in an array. This works fine and dandy until one of the lines contains something like:</p>
  
  <blockquote>
    <p>abcde f (the blank space after f should be read in as part of the
    line).</p>
  </blockquote>
  
  <p>However, <code>scanner.nextLine()</code> seems to disregard this last blank space. I figured I could set my scanner delimiter to <code>\n</code> like so:</p>
  
  <pre><code>scanner.useDelimiter("\n")
  </code></pre>
  
  <p>and then use <code>scanner.Next()</code> from there, but this still doesn't seem to work. I've googled around and taken a look at a few stackoverflow questions. This question here seems to suggest this is not easily done with the scanner class: <a href="https://stackoverflow.com/questions/12994342/how-to-read-whitespace-with-scanner-next">How to read whitespace with scanner.next()</a></p>
  
  <p>Any ideas?  I feel like there's an easy way I'm overlooking.</p>
  
  <p>This is how I'm reading in the lines:</p>
  
  <pre><code>While(scanner.hasNextLine(){
      String nextLine = scanner.nextLine();
  </code></pre>
  
  <p>Using the above example, my string would read <code>abcde f</code>. It will get rid of the empty space at the end.
  I've also tried to use <code>hasNext</code> and <code>next</code>.
  Pardon my formatting, I'm editing on a phone.</p>