I'm trying to do something like it in java (Eclipse Indigo):
input - 16 (integer);
Output - "0016" ;
input - 201 (integer);
Output - "0201" ;
intput - 1716 (integer);
Output - "1716" ;
In VB.net I could use:
dim num as integer
dim str as string
str = Format(num, "0000")
How can I do the same in java? Thanks in advance...
In java, String format() method returns a formatted string using the given locale, specified format string, and arguments. We can concatenate the strings using this method and at the same time, we can format the output concatenated string. Parameter: The locale value to be applied on the format() method.
final String s = String.format("%04d", yourNumber)
.
Note that there is a locale-sensitive version of this method as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With