%[index$][标识][最小宽度]转换方式

[index$]可以用于表示对第index个参数进行格式化,

 // Java代码
String s1=String.format("%3$s,%2$s,%1$s","a","b","c"); // c,b,a

与C#的索引相比,区别在于C#的索引从0开始,并且是不能省略的

Java的索引是从1开始,并且可以省略

// Java代码
String s1=String.format("%s,%s,%s","a","b","c"); // a,b,c 索引可以省略
System.out.println(s1);
String s2=String.format("%3$s,%2$s,%1$s","a","b","c"); // c,b,a 索引从1开始
System.out.println(s2);
// C#
String result = String.Format("{2},{1},{0}","a","b","c"); // c,b,a 注意索引不能省略,并且从0开始
Console.WriteLine(result);

%s转换方式

其实%s可以转换各种类型,其实就是各种类型的 toString()

// Java代码
String s=String.format("%s,%s,%s,%s,%s","a",1,9.2, LocalDateTime.now(),new Date()); // a,1,9.2,2018-02-03T22:36:01.499,Sat Feb 03 22:36:01 CST 2018
System.out.println(s);

与C#对应的,默认转换方式一样

// C#
String result = String.Format("{0},{1},{2},{3}", "a", , 9.2, DateTime.Now); // a,1,9.2,2018/2/3 22:39:52
Console.WriteLine(result);

.Net转Java.08.format的更多相关文章

  1. java.time.format.DateTimeFormatter

    Java的日期与时间 DateTimeFormatter类是Java 8中日期时间功能里,用于解析和格式化日期时间的类,位于java.time.format包下.   1.预定义的DateTimeFo ...

  2. JAVA Stirng.format 使用理解

    JAVA Stirng.format 使用理解前言:项目中需要对一些字符串处理发现format方法的神奇之处一.api才是王道第一种二参使用①public static String format(S ...

  3. java.time.format.DateTimeParseException: Text '2019-10-11 12:30:30' could not be parsed at index 10

    java.time.format.DateTimeParseException: Text '2019-10-11 12:30:30' could not be parsed at index 10 ...

  4. fastjson反序列化LocalDateTime失败的问题java.time.format.DateTimeParseException: Text '2019-05-24 13:52:11' could not be parsed at index 10

    本地java类 import org.springframework.format.annotation.DateTimeFormat; import java.time.LocalDateTime; ...

  5. java String.Format详解

    JDK1.5中,String类新增了一个很有用的静态方法String.format(): format(Locale l, String format, Object... args) 使用指定的语言 ...

  6. JAVA String.format 方法使用介绍

    1.对整数进行格式化:%[index$][标识][最小宽度]转换方式        我们可以看到,格式化字符串由4部分组成,其中%[index$]的含义我们上面已经讲过,[最小宽度]的含义也很好理解, ...

  7. JAVA String.format 方法使用介绍<转>

    在JDK1.5中,String类增加了一个非常有用的静态函数format(String  format, Objece...  argues),可以将各类数据格式化为字符串并输出.其中format参数 ...

  8. java MessageFormat.format 用法

    FormatElement: { ArgumentIndex }:是从0开始的入参位置索引. { ArgumentIndex , FormatType } { ArgumentIndex , Form ...

  9. Java String.Format() 方法及参数说明

    转自:https://blueram.iteye.com/blog/441683 JDK1.5中,String类新增了一个很有用的静态方法String.format():format(Locale l ...

随机推荐

  1. WINDOWS 2008Server 配置nginx 反向代理服务器 安装成服务

    本案例有用过可行 反向代理就是是网站通过一台机器发布到公网,客户访问的时候是直接访问那台代理机器的,然后通过那台机器才访问到内网网站.   0.先要在域名官网上面配置域名对应的IP地址,然后要在自己路 ...

  2. html5的audio实现高仿微信语音播放效果(实际项目)

    HTML部分: <div class="tab-pane fade dialog-record" id="dialogRecord"> <vo ...

  3. Mysql8远程不能登录报错

    mysql8远程登录报错Client does not support authentication protocol requested by server; consider upgrading ...

  4. 51Nod1123 X^A Mod B 数论 中国剩余定理 原根 BSGS

    原文链接https://www.cnblogs.com/zhouzhendong/p/51Nod1123.html 题目传送门 - 51Nod1123 题意 $T$ 组数据. 给定 $A,B,C$,求 ...

  5. Python线程同步

    线程执行 join与setDaemon 子线程在主线程运行结束后,会继续执行完,如果给子线程设置为守护线程(setDaemon=True),主线程运行结束子线程即结束: 如果join()线程,那么主线 ...

  6. sql语句start with connect by prior语法解析

    prior分两种放法: 1 放在子节点端 表示start with 指定的节点作为根节点,按照从上到下的顺序遍历 2 放在父节点端 表示start with指定的节点作为最底层节点,按照从下到上的顺序 ...

  7. html-模仿小米首页定位案例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. POJ1062昂贵的聘礼(经典) 枚举区间 +【Dijkstra】

    <题目链接>                   昂贵的聘礼 Description 年轻的探险家来到了一个印第安部落里.在那里他和酋长的女儿相爱了,于是便向酋长去求亲.酋长要他用1000 ...

  9. Alpha(2/10)

    鐵鍋燉腯鱻 项目:小鱼记账 团队成员 项目燃尽图 冲刺情况描述 站立式会议照片 各成员情况 团队成员 学号 姓名 git地址 博客地址 031602240 许郁杨 (组长) https://githu ...

  10. Stanford CoreNLP使用需要注意的一点

    1.Stanford CoreNLP maven依赖,jdk依赖1.8 <dependency> <groupId>edu.stanford.nlp</groupId&g ...