给字符串左边或右边补0

import org.apache.commons.lang3.StringUtils;

String str = "abc";
//给左边补0
String strL = StringUtils.leftPad(str, 6, "0");
System.out.println(strL);
====>000abc

//给右边补0
String strR = StringUtils.rightPad(str, 6, "0");
System.out.println(strR );
====>abc000

你可能感兴趣的:(java)