String.format (https://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html#syntax)
In your case it will be:
String formatted = String.format("%03d", num);
- 0 – to pad with zeros
- 3 – to set width to 3
More Related Contents:
- Code Wont Run, Got Strange Error [closed]
- How do i find the first un-escaped quotes in Java?
- What is the Java ?: operator called and what does it do?
- How to get a resource id with a known resource name?
- What is the best way to find the user’s home directory in Java?
- How to extract a substring using regex
- Java: Error: variable might not have been initialized
- Spring Boot – Handle to Hibernate SessionFactory
- Reflection type inference on Java 8 Lambdas
- Using JasperReports with a relative path
- How does the Java cast operator work?
- uploading of pdf file
- Manifest merger failed error
- What does InputStream.available() do in Java?
- Java center text in rectangle
- ConcurrentHashMap vs Synchronized HashMap
- Export PDF pages to a series of images in Java
- How to write / update Oracle blob in a reliable way?
- Using curl command in java
- Spring-Data FETCH JOIN with Paging is not working
- How to convert certificate from PEM to JKS?
- Can we call a static method with a null object in Java? If so, how?
- debug java program step by step in Eclipse
- How to override DNS in HTTP connections in Java
- Maven adding mainClass in pom.xml with the right folder path
- How do I put html in a JLabel in java?
- How to disable and enable the scrolling on android ScrollView? [duplicate]
- Java Encode file to Base64 string To match with other encoded string
- Bumblebee Android studio Plugin [id: ‘com.android.application’, version: ‘7.1.0’, apply: false] was not found in any of the following sources:
- Can I replace a Spring bean definition at runtime?