title: What is in.next() doing?
body: <blockquote>
    <p>I am using Scanner class to take input. I am trying to get all the
    words in a line using in.next(). I know it can be done using
    nextLine() but i want to understand how in.next() and in.hasNext()
    works.</p>
  </blockquote>
  
  <pre><code>System.out.println("What is designation");
          String desg = in.next();      
          while(in.hasNext()){
              desg+=in.next();      
          }
  </code></pre>
  
  <p>Gives out put as </p>
  
  <pre><code>What is designation
  member technical staff\n
  ^Z
  Hello abhishek kumarNext year you will be 22Salary is 30000.0Designation is membertechnicalstaff
  </code></pre>
  
  <p>But if i use </p>
  
  <pre><code>System.out.println("What is designation");
          String desg = in.next();      
          if(in.hasNext()){
              desg+=in.next();      
          }
  </code></pre>
  
  <p>It gives output as</p>
  
  <pre><code>What is designation
  member technical staff
  Hello abhishek kumarNext year you will be 22Salary is 44254.0Designation is membertechnical
  </code></pre>
  
  <blockquote>
    <p>In the first case i am getting all the words but it keeps asking for
    next input and i have to specify end of input using CTRL+Z. But in
    second case i am not getting the last word(staff). Please explain.</p>
  </blockquote>