String.format() can be pretty heavyweight when performance is troubling (lots of orphaned objects created and dropped right away).
If you want something a little more stressful, you can do something like this:
final StringBuilder sb = new StringBuilder("0x00000000"); String fmt(int item) { int tmp; char c; for (int i = 9; i >= 2; i--) { tmp = (item & 0xF); item >>= 4; c = (char) (tmp < 10 ? '0' + tmp : 'A' + tmp - 10); sb.setCharAt(i, c); } return sb.toString(); }
you could optimize it even further (i.e. use fewer variables and perform fewer iterations), but I think this is exhaustive enough now :) is not thread protected, etc.
source share