title: What does hasNext() in a While do?
body: <p>I'm new to Java and I'm trying to read data from a .txt file. I've implemented a Scanner object 'in' <code>Scanner in=new Scanner(&quot;file.txt&quot;);</code> and then down the code a while loop to traverse through the content of the file.There are multiple rows of data in the file and in each row there are three strings (security number ,First name ,Last name : 01 Thomas Anderson)</p>
  <pre><code>while(in.hasNext()){
      String ss = in.next();
      String FName=in.next();
      String LName=in.next();
      
      System.out.printf(&quot;SSN: %s, FirstName: %s, LastName: %s \n&quot;,ss,FName,LName);
      }
  </code></pre>
  <p>So, what does the hasNext() method do? Does it look for end of the row or for the last row in the file or.... ?</p>
  <p>Please elaborate on the working of the above snippet (mentioning the next() method too).</p>