I want to format int numbers as hex strings. System.out.println(Integer.toHexString(1)); prints 1 but I want it as 0x00000001. How do I do that?
System.out.println(Integer.toHexString(1));
1
0x00000001
Try this
System.out.println(String.format("0x%08X", 1));
2.1m questions
2.1m answers
60 comments
57.0k users