Can we use String.format() to pad/prefix with a character with desired length?

后端 未结 5 761
广开言路
广开言路 2021-01-04 10:13

Can java.lang.String.format(String str, String str1) be used for adding prefix of a particular character.

I could do this for a number like:



        
5条回答
  •  醉话见心
    2021-01-04 10:42

    You can't use String.format() for padding with arbitrary characters. Perhaps Apache Commons StringUtils.leftPad() would be of use for a concise solution ? Note there's also a StringUtils.rightPad() too.

提交回复
热议问题