String.formate formate有很多格式的应用.
1. %s 替换字符串
"hello limei"
String
.formate("hello %s", "limei")
2. %d 替换十进制整型
%03d (数字前面那补0, 替换3位的整型, 位数不足0补全)
String formate
= "%04d";
System
.out
.println(String
.format(formate
, 546));
System
.out
.println(String
.format(formate
, 9));
System
.out
.println(String
.format(formate
, 92345));
其他
%% --> 百分比 --> %%c --> 字符型%b --> 布尔类型%x --> 整数(16进制)%o --> 整数(8进制)