Anonymous
Anonymous asked in Computers & InternetProgramming & Design · 4 weeks ago

What is nextLine in Java?

1 Answer

Relevance
  • 4 weeks ago

    Hi, kamal.

    In Java, nextLine() is a function of a Scanner. It allows the user to enter a String - with or without spaces - up to end of line, whereas next() only accepts one token and doesn't include spaces.

    Here's an example of the use of nextLine():

    import java.util.Scanner;

    public class ScanTest {

        public static void main (String[] args) {

            // create Scanner object to read keyboard input

            Scanner in = new Scanner (System.in);

            String fullName = "";

            System.out.print ("Enter full name: ");

            fullName = in.nextLine();

            System.out.println ("Your full name is " + fullName);

        }

    }

    • Login to reply the answers
Still have questions? Get your answers by asking now.