当前位置: 首页 > news >正文

外国做营销方案的网站做照片书的网站

外国做营销方案的网站,做照片书的网站,创建平台网站下载链接,腾讯企点官网String.format其实是调用的Formatter.format: public static String format(String format, Object... args) {return new Formatter().format(format, args).toString();} 第一个参数是格式化字符串,第二个参数是可变的被格式化的参数。 我们主要看的是…

String.format其实是调用的Formatter.format:

    public static String format(String format, Object... args) {return new Formatter().format(format, args).toString();}

第一个参数是格式化字符串,第二个参数是可变的被格式化的参数。

我们主要看的是格式化参数的说明:

  • The format specifiers for general, character, and numeric types have the following syntax:
       %[argument_index$][flags][width][.precision]conversion

这个参数是用来格式化通用的、字符串、数字类型,主要说一下每个参数的作用:

% 用于表示这后面将是一个格式化数据的模板,
argument_index$ 表示要作用在第几个参数上,注意一定要加上'$',
flags 以下是flag的对照表,对不同的类型有不同的作用:
  • The following table summarizes the supported flags. y means the flag is supported for the indicated argument types.

    FlagGeneralCharacterIntegralFloating PointDate/TimeDescription
    '-'yyyyyThe result will be left-justified.
    '#'y1-y3y-The result should use a conversion-dependent alternate form
    '+'--y4y-The result will always include a sign
    '  '--y4y-The result will include a leading space for positive values
    '0'--yy-The result will be zero-padded
    ','--y2y5-The result will include locale-specific grouping separators
    '('--y4y5-The result will enclose negative numbers in parentheses

    1 Depends on the definition of Formattable.

    2 For 'd' conversion only.

    3 For 'o', 'x', and 'X' conversions only.

    4 For 'd', 'o', 'x', and 'X' conversions applied to BigInteger or 'd' applied to byte, Byte, short, Short, int and Integer, long, and Long.

    5 For 'e', 'E', 'f', 'g', and'G' conversions only.

    Any characters not explicitly defined as flags are illegal and are reserved for future extensions. 

  • Width

    The width is the minimum number of characters to be written to the output. For the line separator conversion, width is not applicable; if it is provided, an exception will be thrown.

    Precision

    For general argument types, the precision is the maximum number of characters to be written to the output.

    For the floating-point conversions 'a', 'A', 'e','E', and 'f' the precision is the number of digits after the radix point. If the conversion is'g' or 'G', then the precision is the total number of digits in the resulting magnitude after rounding.

    For character, integral, and date/time argument types and the percent and line separator conversions, the precision is not applicable; if a precision is provided, an exception will be thrown.

    Argument Index

    The argument index is a decimal integer indicating the position of the argument in the argument list. The first argument is referenced by "1$", the second by "2$", etc.

    Another way to reference arguments by position is to use the '<' ('\u003c') flag, which causes the argument for the previous format specifier to be re-used. For example, the following two statements would produce identical strings:

       Calendar c = ...;String s1 = String.format("Duke's Birthday: %1$tm %1$te,%1$tY", c);String s2 = String.format("Duke's Birthday: %1$tm %<te,%<tY", c);
最重要的是conversion:
ConversionArgument CategoryDescription
'b', 'B'generalIf the argument arg is null, then the result is "false". Ifarg is a boolean or Boolean, then the result is the string returned by String.valueOf(arg). Otherwise, the result is "true".
'h', 'H'generalIf the argument arg is null, then the result is "null". Otherwise, the result is obtained by invokingInteger.toHexString(arg.hashCode()).
's', 'S'generalIf the argument arg is null, then the result is "null". Ifarg implements Formattable, then arg.formatTo is invoked. Otherwise, the result is obtained by invokingarg.toString().
'c', 'C'characterThe result is a Unicode character
'd'integralThe result is formatted as a decimal integer
'o'integralThe result is formatted as an octal integer
'x', 'X'integralThe result is formatted as a hexadecimal integer
'e', 'E'floating pointThe result is formatted as a decimal number in computerized scientific notation
'f'floating pointThe result is formatted as a decimal number
'g', 'G'floating pointThe result is formatted using computerized scientific notation or decimal format, depending on the precision and the value after rounding.
'a', 'A'floating pointThe result is formatted as a hexadecimal floating-point number with a significand and an exponent. This conversion isnot supported for the BigDecimal type despite the latter's being in thefloating point argument category.
't', 'T'date/timePrefix for date and time conversion characters. See Date/Time Conversions.
'%'percentThe result is a literal '%' ('\u0025')
'n'line separatorThe result is the platform-specific line separator 

示例代码:

package main;public class StringFormat {public static void main(String[] args) {// TODO Auto-generated method stubString format = "Haha.%1$(g%2$s%3$s";Object obj = 100f, object1 = "fdsafds", object2 = new StringFormat();String format2 = String.format(format, obj, object1, object2);System.out.println(format2);// String Format總結// %[argument_index$][flags][width][.precision]conversion 标准表达式}}

运行结果:

Haha.100.000fdsafdsmain.StringFormat@6d6f6e28


http://www.yayakq.cn/news/858371/

相关文章:

  • 做淘宝的人就跟做网站一样外贸建站平台
  • 自适应门户网站模板北京行业网站建设
  • 组建网站专业维护网站的公司
  • 如何解决网站兼容wordpress 授权
  • 门户网站域名是什么意思做网站可以赚钱吗
  • 网站制作前的图片路径即墨网站开发
  • 秀山网站制作深圳市建设工程交易服务中心宝安分中心
  • php 开源企业网站.net网站内容管理系统
  • 明企科技网站建设系统商务网站建设项目的技术可行性
  • 买了域名后做网站该怎么弄网络域名解析错误
  • 网站开发外包方案金融证券网站模板
  • 怎么做网站logo济南卓远网站建设公司
  • 高端网站设计报价表网站上传大马后怎么做
  • 介绍做燕窝的网站上海贸易公司有哪些
  • wap网站域名wordpress微电影模板下载
  • 电子商务网站建设与管理最新试卷快速seo整站优化排行
  • 网站只显示一个网址装潢设计师工资一般多少
  • 涉县网站建设北京远程时代网站建设
  • 门户网站建设投资哪个手游平台折扣最低又安全
  • 网站建设软件哪个最好推广竞价
  • 网站建设技术包括哪些网站做百科
  • 长春门户网站建设二建注册查询系统
  • 制作网站要找什么公司株洲芦淞区
  • 自建网站百度专业3合1网站建设价格
  • 校园网站建设平台在线设计平台的消费者分析
  • 网站推广策划包含哪些内容厦门网站建设网络推广
  • 公司展厅设计公司哪家好一点aso优化前景
  • 苏州做网站哪家公司好在线赚钱平台
  • 番禺网站 优化网站代备案需要多少钱
  • 建设网站后怎么发布毕设做桌面端还是网站