If you are on Java 15 and above,
var minutes = 5var strMinutes = "%02d".formatted(minutes)
where, 2 is the total number of digits you want to display(including zero).
Output: 05
This uses formatted
method part of instance method on Strings called which does the same as the static String.format(str,x,y,z)