Zero padded hexadecimal numbers in Java

A quick recipe, converting an int or long like 65 to a string like 000041. It’s useful for converting integer RGB colors to the common #FFBBCC kind of web encoded colors.

 

int number = 65;
String hexString = String.format("%06X", number);
System.out.println(hexString);

:>