Scanner Nextline Java

The nextLine method in Java

As we can get from the name, we can simply say that we are going to get the line as an input. So, whenever we are in such a situation, that we need some line from the user as input, we can make use of the nextLine method.

Below is the implementation of the nextLine() method –

Read input till the end of line (nextLine method)

package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String text_with_spaces = scanner.nextLine();
System.out.println(text_with_spaces);
}
}

So, now if you try implementing this program, you can see that the spaces are also considered.