in.nexLine() is used to accept the entire String sentence avialable to the scanner object, before a line break, and stored in the string variable.
in.next() however accepts only the next token….i.e. only the word avialable( the characters avialable to thr scanner object in before a delimiter(by default a whitespace and linebreak are delimiters for scanner class)occurs).
Consider this example:-
If you Enter: Hi I amRahul
using:str = in.nextLine(); the entire sentence is stored in str.
using:str1= in.next();only the first word (here Hi) enters into str1.
Therefore, Output:
str= Hi I am Rahul
str1= Hi