Java.util.Scanner.hasNextLine() 方法
描述
如果此扫描仪的输入中有另一行,则 java.util.Scanner.hasNextLine() 方法返回 true。 此方法可能会在等待输入时阻塞。 扫描仪不会超过任何输入。
声明
以下是 java.util.Scanner.hasNextLine() 方法的声明
public boolean hasNextLine()
参数
NA
返回值
当且仅当此扫描仪有另一行输入时,此方法才返回 true
异常
IllegalStateException − 如果此扫描仪已关闭
示例
下面的例子展示了 java.util.Scanner.hasNextLine() 方法的使用。
package com.tutorialspoint;
import java.util.*;
public class ScannerDemo {
public static void main(String[] args) {
String s = "Hello World! \n 3 + 3.0 = 6 ";
// create a new scanner with the specified String Object
Scanner scanner = new Scanner(s);
// print the next line
System.out.println("" + scanner.nextLine());
// check if there is a next line again
System.out.println("" + scanner.hasNextLine());
// print the next line
System.out.println("" + scanner.nextLine());
// check if there is a next line again
System.out.println("" + scanner.hasNextLine());
// close the scanner
scanner.close();
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
Hello World! true 3 + 3.0 = 6 false

