I won't say much nonsense, the key code is as follows:
package cn.com.songjy;import java.text.NumberFormat;//Java add 0 public class NumberFormatTest {public static void main(String[] args) {// Insert the data to be tested int i = 1;// Get an instance of NumberFormat NumberFormat nf = NumberFormat.getInstance();// Set whether to use grouping nf.setGroupingUsed(false);// Set the maximum integer digit nf.setMaximumIntegerDigits(4);// Set the minimum integer digit nf.setMinimumIntegerDigits(4);// Output test statement System.out.println(nf.format(i));}}/** * Implementation of automatically supplementing 0 in Java to convert numeric strings. * */ public class TestStringFormat { public static void main(String[] args) { int youNumber = 1; // 0 represents the previous supplement 0 // 4 represents the length of 4 // d represents the parameter as a positive number String str = String.format("%04d", youNumber); System.out.println(str); // 0001 } }// The flow number is added 1 and the flow number is returned, and the flow number is 4private static final String STR_FORMAT = "0000"; public static String haoAddOne_2(String liuShuiHao){Integer intHao = Integer.parseInt(liuShuiHao);intHao++;DecimalFormat df = new DecimalFormat(STR_FORMAT);return df.format(intHao);}Okay, the above code is about the implementation code for adding 0 or spaces to Java String strings. It is very good. I hope it will be helpful to everyone. If you have any questions, please leave me a message. The editor will reply you in time. Thank you very much for your support for the Wulin Network website!