How can I pad an integer with zeros on the left?

后端 未结 16 2528
南旧
南旧 2020-11-21 06:31

How do you left pad an int with zeros when converting to a String in java?

I\'m basically looking to pad out integers up to 9999

16条回答
  •  生来不讨喜
    2020-11-21 06:57

    If you for any reason use pre 1.5 Java then may try with Apache Commons Lang method

    org.apache.commons.lang.StringUtils.leftPad(String str, int size, '0')
    

提交回复
热议问题