Java扫描仪具有示例的NextNextLine()方法
扫描仪类hasNextLine()方法
hasNextLine()方法在java.util包中可用。
hasNextLine()方法用于检查此Scanner输入中是否存在其他任何行。
hasNextLine()方法是一个非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
在检查给定输入中存在下一行时,hasNextLine()方法可能会引发异常。
IllegalStateException:如果未打开此扫描器,则可能引发此异常。
语法:
public boolean hasNextLine();
参数:
它不接受任何参数。
返回值:
该方法的返回类型为boolean,当输入中存在换行时返回true,否则返回false。
示例
//Java程序演示示例
//hasNextLine()扫描程序的布尔方法的说明
import java.util.*;
public class HasNextLineOfScanner {
public static void main(String[] args) {
String str = "Hi, [IncludeHelp] +\n 10.0 true ";
//实例化Scanner对象
//给定的字符串str-
Scanner sc = new Scanner(str);
//显示str-
System.out.println("sc.nextLine(): " + sc.nextLine());
//通过使用hasNextLine()方法是
//检查此扫描器是否下一个令牌
//是否包含有效的有效另一行
boolean status = sc.hasNextLine();
System.out.println("sc.hasNextLine(): " + sc.hasNextLine());
//通过使用close()方法是
//关闭扫描仪对象
sc.close();
}
}输出结果
sc.nextLine(): Hi, [IncludeHelp] + sc.hasNextLine(): true