Format String become xxx1, xx10 or 1###, 10## etc
formatting, java, string
Solution
NumberFormat nf = new DecimalFormat("0000");
System.out.println(nf.format(10));
This prints "0010".
Problem
I have following numbers : 1, 2, 3, 4, 10 But I want to print those numbers like this: ``` 0001 0002 0003 0004 0010 ``` I have searched in Google. the keyword is number format. But I've got nothing, I just get, format decimal such ass `1,000,000.00`. I hope you can suggest me a reference or give me something to solve this problem. Thanks Edit, we can use NumberFormat, or String.format("%4d", somevalue); but it just for adding `0` character before integer. How If I wanna use character such as `x`, `#` or maybe `whitespace`. So the character become: `xxxx1` `xxx10` or `####1` `###10` or `1####` `10###`