當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Java.util.Scanner.toString()用法及代碼示例


描述

這個java.util.Scanner.toString()方法返回此 Scanner 的字符串表示形式。 Scanner 的字符串表示包含可能對調試有用的信息。確切的格式未指定。

聲明

以下是聲明java.util.Scanner.toString()方法

public String toString()

參數

NA

返回值

此方法返回此掃描儀的字符串表示形式

異常

NA

示例

下麵的例子展示了 java.util.Scanner.toString() 方法的用法。

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());

      // display information about this scanner
      System.out.println(""+scanner.toString());

      // close the scanner
      scanner.close();
   }
}

讓我們編譯並運行上麵的程序,這將產生以下結果——

Hello World! 3 + 3.0 = 6.0 true 
java.util.Scanner[delimiters = \p{javaWhitespace}+][position = 32][match valid = true][need input = false][source closed = true][skipped = false][group separator = \.][decimal separator = \,][positive prefix = ][negative prefix = \Q-\E][positive suffix = ][negative suffix = ][NaN string = \Q?\E][infinity string = \Q?\E]

相關用法


注:本文由純淨天空篩選整理自 Java.util.Scanner.toString() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。