ipohfly
ipohfly

Reputation: 2009

String.format equivalent in Java 1.4

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

Answers (4)

ilalex
ilalex

Reputation: 3078

Retrotranslator supports String.format translation to JDK 1.4

Upvotes: 0

maba
maba

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

Keppil
Keppil

Reputation: 46219

You could use something like this snippet:

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

Upvotes: 3

Peter Lawrey
Peter Lawrey

Reputation: 533500

You need to use Integer.toHexString(int) and pad the text yourself.

Upvotes: 1

Related Questions