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

参考链接: Python | 输出格式化 output format

格式化程序类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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/540599.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

arm tbh_TBH的完整形式是什么?

arm tbhTBH:说实话 (TBH: To Be Honest) TBH is an abbreviation of "To Be Honest". It is internet slang which generally used as an acronym or hashtag over the internet on social media networking sites like Facebook, Instagram, Twitter, Yo…

异常:fatal: unable to access 'https://git.oschina.net/pcmpcs/library.git/': Could not resolve host...

git fork项目时出现的异常. 原因: 我以前用的是ssh地址做的远程通信地址,而这次是用的是https,因为很久没用,所以忘记了以前是用ssh的了。解决方案一:复制ssh协议的地址,然后再关联远程仓库。并且在VCS下的git下的Rem…

计数器数组_子数组计数

计数器数组Problem statement: 问题陈述: Given an array of N positive integers a1, a2, ..., an. The value of each contiguous subarray of a given array is the maximum element present in that subarray. The task is to return the number of subarrays…

[转载] 列表、元组及通用序列操作

参考链接: Python | 重点数据类型 (字符串,列表,元组,迭代)(String, List, Tuple, Iteration) 序列是Python中最基本的数据结构(一些基本特性类似于C中的数组模板类),序列中的每一个元素都有相…

onActivityResult()后onresume()

当你调用完一个存在的activity之后,onActivityResult将会返回以下数据:你调用时发出的requestCode、被调用activity的结果标志resultCode(如RESULT_OK)和其他的额外数据。我们期望的都是得到RESULT_OK,表示调用成功&am…

java反射用法示例_Java包| 类型,用法,示例

java反射用法示例配套 (Packages) Packages in Java is simply a mechanism to encapsulate (i.e. to put in a short and concise form) a group of classes,interfaces,enumerations, sub packages, etc. In real world, application is developed in such a manner so that …

[转载] python 元组tuple - python基础入门(14)

参考链接: Python元组Tuple 目录 一.元组tuple定义 二.元组tuple查询 三.元组tuple不支持删除/修改数据 四.元组tuple与列表list的相互转换 五.重点总结 在上一篇文章中我们讲解了关于python列表List的相关内容,今天给大家解释一下列表List的…

MaxCompute 2.0—从ODPS到MaxCompute

从ODPS到MaxCompute-阿里大数据的进化之路是一个商用大数据系统发展史,一个商业大数据系统要解决的问题有可靠性,高性能,安全性等等六个方面。内部产品名ODPS的MaxCompute,是阿里巴巴内部发展的一个高效能、低成本,完全…

python数值类型_Python数值类型

python数值类型In programming, Data Types are an essential concept. Data of various types can be stored in variables as per the task we want the variables to perform. 在编程中,数据类型是必不可少的概念。 根据我们希望变量执行的任务,各种类…

[转载] Python高级变量(列表、元组、字典、字符串、公共方法)

参考链接: Python | 重点数据类型 (字符串,列表,元组,迭代)(String, List, Tuple, Iteration) 文章目录 高级变量类型目标知识点回顾 01. 列表1.1 列表的定义1.2 列表常用操作del 关键字(科普)关键字、函数…

python 操作mongodb数据库参考文档

参考文档链接:https://pypi.python.org/pypi/pymongo pymongo的参考文档http://api.mongodb.com/python/current/tutorial.html mongoengine的参考文档:https://pypi.python.org/pypi/mongoengine#downloads Flask-MongoEngine的参考文档:htt…

php eot eod_EOD的完整形式是什么?

php eot eodEOD:一天结束 (EOD: End Of Day) EOD is an abbreviation of "End Of Day". EOD是“ End Of Day”的缩写 。 It is an expression, which is commonly used in the Gmail platform. In a particular mail, if the sender wants to give the d…

[转载] python元组 tuple

参考链接: Python元组Tuple 类型特点:可以存放多个、 可以重复的,有顺序的数据,数据不可变。 如果项目中需要定义多个数据到一个变量中存放 存放的数据,在项目运行过程中,会发生数据的增加、修改、删除…

aio nio aio_AIO的完整形式是什么?

aio nio aioAIO:多合一 (AIO: All-in-one) AIO is an abbreviation of "all-in-one", which is also known as an MFP (multi-function product/printer/peripheral), multi-functional or multi-function device (MFD). It is a workplace machine that …

[转载] python基础入门二

参考链接: Python集合Set 写代码,有如下变量,请按照要求实现每个功能 (共6分,每小题各0.5分) name ” aleX” 1)移除 name 变量对应的值两边的空格,并输出处理结果 2) 判断 name 变量对应的值是否以 “al” 开头,并输出结果
…

组合数据类型练习,英文词频统计实例上

1、字典实例:建立学生学号成绩字典,做增删改查遍历操作。 建立: d{0001:99,0003:89,0004:98,0005:100,0006:78} 增:d[0002]79 删:d.pop(0001) 改:d[0004]100 查:print(d[0002]) 遍历操作&#x…

茱莉亚分形_茱莉亚的NaN Constant

茱莉亚分形Julia| NaN / Nan64常数 (Julia | NaN/Nan64 Constant) Nan / Nan64 is a constant of the Float64 type in Julia programming language, it represents "not-a-number" value. Nan / Nan64是Julia编程语言中Float64类型的常量,它表示“非数字…

[转载] Python3 数组

参考链接: Python中的Array | 数组1(简介和功能) 一、list和array的区别 Python的数组通过Numpy包的array实现。 Python里二者最大的区别是,list可以存储不同类型的数据,而array只能存储相同类型的数据。 import numpy #直接定义 a […

201671010128 2017-09-24《Java程序设计》之继承

1.继承的概念及理解: 继承是java面向对象编程技术的一块基石,因为它允许创建分等级层次的类。继承就是子类继承父类的特征和行为,使得子类对象(实例)具有父类的实例域和方法,或子类从父类继承方法&#xff…

紫外线的形式是什么?

紫外线:紫外线 (UV: Ultraviolet) UV is an abbreviation of Ultraviolet. In RO water purifiers, the bacteria or germs which are present in the water cannot get killed by reverse osmosis process but this process can banish the dissolved solids and i…