Java int转String位数不足左补0(共12位)

方法一:
sendXmlLen = String.format("%012d", sendXmlStr.length());

方法二:
StringBuilder lengthStr = new StringBuilder(Objects.toString(sendXmlStr.length()));
int length = lengthStr.length();
if (length < 12) {
int count = 12 - length;
for (int i = 0; i < count; i++) {
lengthStr.insert(
0, “0”
);
}
}
System.err.println(lengthStr.toString());

你可能感兴趣的:(代码,string)