扫描仪类toString()方法 (Scanner Class toString() method)

  • toString() method is available in java.util package.

    toString()方法在java.util包中可用。

  • toString() method is used to string denotation of this Scanner and it contains information related to tracing.

    toString()方法用于对此扫描程序进行字符串表示,并且包含与跟踪有关的信息。

  • toString() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

    toString()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。

  • toString() method does not throw an exception at the time of string denotation of this Scanner.

    在此扫描程序的字符串表示形式时, toString()方法不会引发异常。

Syntax:

句法:

    public String toString();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of the method is String, it returns string representation of this Scanner.

该方法的返回类型为String ,它返回此Scanner的字符串表示形式。

Example:

例:

// Java program to demonstrate the example
// of String toString() method of Scanner
import java.util.*;
public class ToStringOfScanner {public static void main(String[] args) {String str = "Hi, true \n IncludeHelp! 8 + 2.0f = 10.0f";
// Instantiate Scanner with the
// given str
Scanner sc = new Scanner(str);
// Display Scanner
System.out.println("sc.nextLine(): " + sc.nextLine());
// By using toString() method is to
// represent string for this Scanner
System.out.println("sc.toString(): " + sc.toString());
// close the scanner
sc.close();
}
}

Output

输出量

sc.nextLine(): Hi, true
sc.toString(): java.util.Scanner[delimiters=\p{javaWhitespace}+][position=10][match valid=true][need input=false][source closed=false][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\QNaN\E][infinity string=\Q∞\E]

翻译自: https://www.includehelp.com/java/scanner-tostring-method-with-example.aspx

Java扫描仪toString()方法及示例相关推荐

  1. Java IOUtils.copy方法代码示例(亲测)

    本文整理汇总了Java中org.apache.commons.io.IOUtils.copy方法的典型用法代码示例.如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java I ...

  2. Java之toString()方法详解

    Java之toString()方法详解 Java中 toString()方法在Object类中和Intent类中都有定义,作用类似,但显示形式有点区别 一.Object类中toString()方法 t ...

  3. java Boolean toString()方法

    java Boolean toString()方法 声明 public static String toString(boolean b) 返回值 返回指定布尔值的字符串表达形式 /*** Creat ...

  4. Java图片扫描仪_Java扫描仪useDelimiter()方法及示例

    扫描仪类useDelimiter()方法 语法:public Scanner skip(Pattern patt); public Scanner skip(String patt);useDelim ...

  5. Java调用tostring方法分析_Java对象toString()方法

    对象的字符串表示以可读格式包含有关对象状态的信息. Object类的toString()方法表示字符串中类的对象.Object类提供了toString()方法的默认实现. 它返回一个以下格式的字符串: ...

  6. JAVA中toString方法的作用(转)

    因为它是Object里面已经有了的方法,而所有类都是继承Object,所以"所有对象都有这个方法". 它通常只是为了方便输出,比如System.out.println(xx),括号 ...

  7. [转载] java重写toString()方法

    参考链接: 在Java中重写toString() 前言: 在你兴高采烈的写完一个类,创建测试类时,创建对象,传入参数,调用对象,以为会得到参数值,但突然发现输出的是" 类名@什么东东?(其实 ...

  8. JAVA基础——toString()方法,java基础面试笔试题

    我总结出了很多互联网公司的面试题及答案,并整理成了文档,以及各种学习的进阶学习资料,免费分享给大家. 扫描二维码或搜索下图红色VX号,加VX好友,拉你进[程序员面试学习交流群]免费领取.也欢迎各位一起 ...

  9. JAVA中toString方法的作用

    一句话概括:就是可以把实体类,或者其他类,以字符串或者规定的方式输出, 如果用了toString那么就会这样输出User 否则就会输出: 因为它是Object里面已经有了的方法,而所有类都是继承Obj ...

最新文章

  1. 我为什么强烈反对程序员加班?
  2. 自动化运维工具puppet(1)
  3. pip镜像源永久设置成国内镜像源,提升下载速度
  4. python3.4 安装numpy报错_python2.7安装numpy报错:is not a supported wheel on...
  5. CodeIgniter笔记3
  6. SpringMVC第六篇【校验、统一处理异常】
  7. SHELL基础命令大全
  8. C语言学习(一)C语言能干什么?为什么要学习C语言?
  9. 【智能安防监控补光灯调光芯片方案】单节锂电降压恒流驱动芯片FP8013 最大输出3A体积小/静态功耗低/效率高/支持无频闪调光
  10. 物联网安全综述报告之感知层认证机制
  11. er2100虚拟服务器,华三er2100n路由器恢复出厂设置
  12. 入门 HTML JavaScript Jquery学习回顾 有小案例
  13. 后端Java人必备:30个优化SQL的良心建议
  14. 擎创喜报 | 名单公布!恭喜入选!
  15. 月薪两万的“土豪”师兄,加个微信吧!
  16. 大学生笔记本购买指南——扫盲版(2019)
  17. ios android md5加密,iOS中使用MD5加密
  18. 卷积神经网络图像分类的性能评估指标有哪些
  19. MBR格式转GPT格式阿里云云盘在线扩容
  20. popupmenu用法 matlab,如何在下拉菜单popupmenu加入以下代码

热门文章

  1. micopython 18b20_MicroPython控制8*8LED点阵显示温度
  2. python中 12_python编程中常用的12种基础知识总结
  3. java读取邮箱附件_使用javamail获取附件内容
  4. pytorch 命令行运行_PyTorch简介与相关安装
  5. win10 利用安装包 安装 ssh
  6. Qt自定义QML模块
  7. 上海交通大学2006年各学院本科生平均薪酬统计
  8. Linux的启动流程简析(以Debian为例)
  9. 大道至简: 拉新、促活和留存
  10. IIS 伪静态下 利用PHP获取 网址后缀