格式化程序类toString()方法 (Formatter Class toString() method)

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

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

  • toString() method is for the string representation of this Formatter.

    toString()方法用于此Formatter的字符串表示形式。

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

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

  • toString() method may throw an exception at the time of string representation of this Formatter.

    在此Formatter的字符串表示形式时, toString()方法可能会引发异常。

    FormatterClosedException: This exception may throw when this formatter close by calling its close() method.

    FormatterClosedException :当此格式化程序通过调用其close()方法关闭时,可能会抛出此异常。

Syntax:

句法:

    public String toString();

Parameter(s):

参数:

  • It does not accept any parameter.

    它不接受任何参数。

Return value:

返回值:

The return type of this method is String, it works on the destination for the output.

此方法的返回类型为String ,它在输出的目标上起作用。

Example:

例:

// Java program is to demonstrate the example of
// toString() method of Formatter
import java.util.*;
public class ToStringOfFormatter {public static void main(String[] args) {// Instantiates a StringBuffer and Formmatter
// object
StringBuffer sb = new StringBuffer();
Formatter formatt = new Formatter(sb, Locale.UK);
// By using format() method is to format
// a string
formatt.format("Hi %s !", "IncludeHelp");
// Display Formatted String
System.out.println(formatt);
// By using toString() method is to
// represent the string formatted by
// this Formatter
System.out.println("formatt.toString(): " + formatt.toString());
}
}

Output

输出量

Hi IncludeHelp !
formatt.toString(): Hi IncludeHelp !

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

Java Formatter toString()方法与示例相关推荐

  1. [转载] Java Formatter toString()方法与示例

    参考链接: Python | 输出格式化 output format 格式化程序类toString()方法 (Formatter Class toString() method) toString() ...

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

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

  3. Java之toString()方法详解

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

  4. java Boolean toString()方法

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

  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. Blender从头到尾创建一个低多边形场景学习教程
  2. python里面self_Python中的self详细解析
  3. 2017年卖掉全副身家买比特币,全家人一起游牧……这个企业家好疯狂!
  4. 【Arduino】按键按下执行不同模式程序
  5. 上海交大计算机学院张卫东,张卫东
  6. C#连接MySQL数据库实例
  7. json.tojsonstring 导致cpu飙高_阿里调试神器立功了!进程导致Kubernetes节点CPU飙高的排查与解决...
  8. 夏至与北回归线的故事
  9. 百度网盘图片直链的php解析代码
  10. 不用找,你想要的家具贴图素材都在这里
  11. 模糊自适应整定PID控制
  12. Oracle将监听服务注册到集群中,110 ORACLE实例配置多个监听器
  13. 视频教程-玩转Python-Python3基础入门-Python
  14. huobi程序化交易项目
  15. c语言51单片机调节led亮度,51单片机中用PWM控制LED亮度调节
  16. 百练 2755:神奇的口袋
  17. 冰羚-IceOryx FAQ翻译
  18. ubc 文学院 计算机,UBC大学电气与计算机教授获加拿大国家最高科学奖
  19. 团队负责人(team leader)职责
  20. appnium环境搭建

热门文章

  1. 跨域获取后台数据undefined_同源策略amp;JSONP跨域
  2. 东京战纪服务器维护中,东京战纪7月21维护公告 当前测试进度介绍
  3. 计算机硬盘中病毒以后怎么办,计算机中病毒,格式化整个硬盘后还有?怎么办?...
  4. centos daemonize_手把手教你在centos上配置Django项目(超详细步骤)
  5. centos常用命令_二、Docker镜像是什么?Docker常用命令
  6. MYSQL的集群的安装与配置(mysql-5.1.21)
  7. 深度学习框架PyTorch一书的学习-第四章-神经网络工具箱nn
  8. 设计几个简单的汇编函数
  9. 毕设开发日志2017-12-01-Scan超时
  10. python中import的作用_python使用import报错是什么原因