java.text.MessageFormat格式化字符串时的小技巧 public static void main(String[] args) throws InterruptedException { MessageFormat form = new MessageFormat( "{2,date,yyyy-MM-dd HH:mm:ss.SSS} The disk \"{1}\" contains {0,number,#.##} file(s).{3}");…
java.text.MessageFormat类MessageFormat提供一种语言无关的方式来组装消息,它允许你在运行时刻用指定的参数来替换掉消息字符串中的一部分.你可以为MessageFormat定义一个模式,在其中你可以用占位符来表示变化的部分: import java.text.MessageFormat; import java.util.Date; public class MessageFormatTest { public static void main(String[] a…
String 类的静态方法format()方法用于创建格式化字符串,format()方法有两种重载形式: format(String fromat,Object...args) 该方法使用指定的格式字符串和参数返回一个格式化的字符串,格式化后的新字符串使用本地默认的语言环境. 语法:String.format(String.format,Object...args) Date date = new Date(); String.format("%tH",date); format(Lo…