java.util.Scanner类的toString()方法返回此Scanner的字符串表示形式。未指定确切的格式。
用法:
public String toString()
返回值:此函数返回此扫描器的字符串表示形式。
以下示例程序旨在说明上述函数:
示例1:
// Java program to illustrate the
// toString() method of Scanner class in Java
import java.util.*;
public class GFG1 {
public static void main(String[] argv)
throws Exception
{
String s = "GeeksForGeeks - "
+ "A Computer Science Portal for Geeks";
// create a new scanner
// with the specified String Object
Scanner scanner = new Scanner(s);
// print a line of the scanner
System.out.println("Scanner String: \n"
+ scanner.nextLine());
// display information about this scanner
System.out.println("\nString representation "
+ "of this Scanner:\n"
+ scanner.toString());
// close the scanner
scanner.close();
}
}
输出:
Scanner String: GeeksForGeeks - A Computer Science Portal for Geeks String representation of this Scanner: java.util.Scanner[delimiters=\p{javaWhitespace}+] [position=51][match valid=true][need input=false] [skipped=false][group separator=\,] [decimal separator=\.][positive prefix=] [negative prefix=\Q-\E][positive suffix=] [negative suffix=][NaN string=\Q?\E][infinity string=\Q?\E]
参考: https://docs.oracle.com/javase/7/docs/api/java/util/Scanner.html#toString()
相关用法
- Java Scanner nextBoolean()用法及代码示例
- Java Scanner hasNextShort()用法及代码示例
- Java Scanner hasNextLong()用法及代码示例
- Java Scanner nextInt()用法及代码示例
- Java Scanner reset()用法及代码示例
- Java Scanner nextByte()用法及代码示例
- Java Scanner nextBigInteger()用法及代码示例
- Java Scanner nextShort()用法及代码示例
- Java Scanner radix()用法及代码示例
- Java Scanner useRadix()用法及代码示例
- Java Scanner close()用法及代码示例
- Java Scanner hasNextBigInteger()用法及代码示例
- Java Scanner hasNextDouble()用法及代码示例
- Java Scanner hasNextBigDecimal()用法及代码示例
- Java Scanner hasNextBoolean()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 Scanner toString() method in Java with Examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。