Java.util.Scanner.findInLine() 方法
描述
java.util.Scanner.findInLine(String pattern) 方法尝试查找从指定字符串构造的模式的下一个匹配项,忽略分隔符。
声明
以下是 java.util.Scanner.findInLine() 方法的声明
public String findInLine(String pattern)
参数
pattern − 指定要搜索的模式的字符串
返回值
此方法返回与指定模式匹配的文本。
异常
IllegalStateException − 如果此扫描仪已关闭
示例
下面的例子展示了 java.util.Scanner.findInLine() 方法的使用。
package com.tutorialspoint;
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);
// find a string "World"
System.out.println("" + scanner.findInLine("World"));
// print the rest of the string
System.out.println("" + scanner.nextLine());
// close the scanner
scanner.close();
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
World ! 3 + 3.0 = 6

