String.format equivalent in Java 1.4

formatting, java, java1.4

Solution

You could use something like this snippet:

String hexString = Integer.toHexString(octet);
if (hexString.length() < 2) {
    hexString = "0" + hexString;
}

Problem

Currently i have a method calling `String.format()` in Java 5 and it's working perfectly ``` String.format("%02x", octet) //octet is a int type ``` However due to some issue we need to deploy this code in a JDK 1.4 environment, and String.format doesn't exists in 1.4. Anyone knows any alternative way to perform this function?

Original source