Home / Questions / What is the difference between the Scanner class functions next() and nextLine()?
Explanatory Question

What is the difference between the Scanner class functions next() and nextLine()?

👁 80 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

next() nextLine()
It reads the input only till space so it can read only a single word. It reads the input till the end of line so it can read a full sentence including spaces.
It places the cursor in the same line after reading the input. It places the cursor in the next line after reading the input.