Reputation: 2009
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?
Upvotes: 7
Views: 7120
Reputation: 48055
I think you should take a look at Retroweaver which lets you deploy Java 1.5 on a 1.4 JVM.
Upvotes: 0
Reputation: 46219
You could use something like this snippet:
String hexString = Integer.toHexString(octet);
if (hexString.length() < 2) {
hexString = "0" + hexString;
}
Upvotes: 3
Reputation: 533500
You need to use Integer.toHexString(int)
and pad the text yourself.
Upvotes: 1