简体   繁体   中英

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?

You could use something like this snippet:

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

您需要使用Integer.toHexString(int)并自己填充文本。

我想你应该看看Retroweaver ,它允许你在1.4 JVM上部署Java 1.5。

Retrotranslator支持String.format转换为JDK 1.4

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM