java.util.Scanner类的delimiter()方法返回此Scanner当前用于匹配定界符的Pattern。
用法:
public Pattern delimiter()
返回值:该函数返回扫描仪的定界图案。
以下示例程序旨在说明上述函数:
示例1:
// Java program to illustrate the
// delimiter() method of Scanner class in Java
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "Geeksforgeeks has Scanner Class Methods";
// create a new scanner
// with the specified String Object
Scanner scanner = new Scanner(s);
// prints the next line of the string
System.out.println("Scanner String: \n"
+ scanner.nextLine());
// print the delimiter this scanner is using
System.out.println("\nDelimiter being used in Scanner: "
+ scanner.delimiter());
// Close the scanner
scanner.close();
}
}
输出:
Scanner String: Geeksforgeeks has Scanner Class Methods Delimiter being used in Scanner: \p{javaWhitespace}+
示例2:
// Java program to illustrate the
// delimiter() method of Scanner class in Java
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "Geeksforgeeks.has.Scanner.Class.Methods";
// create a new scanner
// with the specified String Object
Scanner scanner = new Scanner(s);
// Set the delimiter to "."
scanner.useDelimiter(".");
// prints the next line of the string
System.out.println("Scanner String: \n"
+ scanner.nextLine());
// print the delimiter this scanner is using
System.out.println("\nDelimiter being used in Scanner: "
+ scanner.delimiter());
// Close the scanner
scanner.close();
}
}
输出:
Scanner String: Geeksforgeeks.has.Scanner.Class.Methods Delimiter being used in Scanner: .
参考: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#delimiter()
相关用法
- Java Scanner hasNextFloat()用法及代码示例
- Java Scanner hasNextDouble()用法及代码示例
- Java Scanner hasNextBoolean()用法及代码示例
- Java Scanner reset()用法及代码示例
- Java Scanner hasNextBigDecimal()用法及代码示例
- Java Scanner hasNextBigInteger()用法及代码示例
- Java Scanner nextLong()用法及代码示例
- Java Scanner nextBoolean()用法及代码示例
- Java Scanner close()用法及代码示例
- Java Scanner useRadix()用法及代码示例
- Java Scanner hasNextLine()用法及代码示例
- Java Scanner hasNextInt()用法及代码示例
- Java Scanner ioException()用法及代码示例
- Java Scanner nextDouble()用法及代码示例
- Java Scanner nextInt()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 Scanner delimiter() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。