Java.util.Scanner.useDelimiter() 方法
描述
java.util.Scanner.useDelimiter(String pattern) 方法将此扫描器的定界模式设置为从指定字符串构造的模式。
声明
以下是 java.util.Scanner.useDelimiter() 方法的声明
public Scanner useDelimiter(String pattern)
参数
pattern − 指定分隔模式的字符串
返回值
此方法返回此扫描仪
异常
NA
示例
下面的例子展示了 java.util.Scanner.useDelimiter() 方法的使用。
package com.tutorialspoint;
import java.util.*;
public class ScannerDemo {
public static void main(String[] args) {
String s = "Hello World! 3 + 3.0 = 6.0 true ";
// create a new scanner with the specified String Object
Scanner scanner = new Scanner(s);
// print a line of the scanner
System.out.println("" + scanner.nextLine());
// change the delimiter of this scanner
scanner.useDelimiter("Wor");
// display the new delimiter
System.out.println("" + scanner.delimiter());
// close the scanner
scanner.close();
}
}
让我们编译并运行上面的程序,这将产生以下结果 −
Hello World! 3 + 3.0 = 6.0 true Wor

