Or maybe make it more generic and allow to specify the base as well, that’s more along the line of existing toString() methods of numbers.
besides convinience, I wonder if it would actually improve performance, how good is the JIT and EA in that case, did you run some benchmarks?
Gruss
Bernd
--
http://bernd.eckenfels.net
Von: core-libs-dev <[email protected]> im Auftrag von 温绍锦(高铁) <[email protected]>
Gesendet: Samstag, September 30, 2023 2:07 PM
An: core-libs-dev <[email protected]>
Betreff: Adding appendHex method to StringBuilder
Gesendet: Samstag, September 30, 2023 2:07 PM
An: core-libs-dev <[email protected]>
Betreff: Adding appendHex method to StringBuilder
There are many combinations of `append(Integer.toHexString(i))` and `append(Long.toHexString(i))` in the JDK code. I request to add method `appendHex(int)` and `appendHex(int)` to StringBuilder and StringBuffer. This can reduce duplicate code within the JDK and will also be useful to users.
I submitted a PR ( https://github.com/openjdk/jdk/pull/15998 ), including the code and tests for the new method. I also replaced the code that uses the append + toHexString combination inside the JDK with appendHex.
