Javatpoint Logo
Javatpoint Logo

Java Scanner nextLine() Method

The nextLine() method of Java Scanner class is used to get the input string that was skipped of the Scanner object.

Syntax

Following is the declaration of nextLine() method:

Parameter

This method does not accept any parameter.

Returns

The nextLine() method returns the the line that was skipped.

Exceptions

NoSuchElementException- It will thrown this Exception if no line was found.

IllegalStateException- It will thrown this Exception if the innvocation is done after Scanner is closed.

Compatibility Version

Java 1.5 and above

Example 1

Output:

Enter Item ID: A151
Enter Item price: 3473.75
Price of Item A151 is $3473.75

Example 2

Output:

hasNextLine
public boolean hasNextLine()
IllegalStateException

Example 3

Output:

Facebook.com 
true
 1 + 1 = 2.0 
true
 JavaTpoint.com 
false
Next TopicJava Scanner Class



Help Others, Please Share

facebook twitter pinterest