java.util.Scanner.hasNextLine() 如果有另一条线在此scanner的输入方法返回true。在等待输入此方法可能阻塞。scanner不执行任何输入。
声明
以下是java.util.Scanner.hasNextLine()方法的声明
public boolean hasNextLine()
参数
-
NA
返回值
当且仅当此scanner输入另一行此方法返回true
异常
-
IllegalStateException -- 如果此scanner 已关闭
例子
下面的示例演示java.util.Scanner.hasNextLine()方法的用法。
package com.yiibai; import java.util.*; public class ScannerDemo { public static void main(String[] args) { String s = "Hello World! 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