Converting an integer to a hexadecimal string representation in Java I have rolled my own Java method for converting ints to the hexadecimal Strings:
import java.util.Arrays;
import java.util.Random;

public class Main {
    
    /**
     * Converts the input integer into its textual hexadecimal representation.
     * 
     * @param a the integer to convert.
     * @return the string representing {@code a} in hexadecimal notation.
     */
    public static String intToHexString(int a) {
        StringBuilder stringBuilder = new StringBuilder(Integer.BYTES * 2);
        boolean inLeadingZeros = true;
        
        while (a != 0) {
            char digit = toHexChar(a &amp; 0xf);
            a &gt;&gt;&gt;= 4;
            
            if (inLeadingZeros) {
                if (digit != 0) {
                    inLeadingZeros = false;
                    stringBuilder.append(digit);
                }
            } else {
                stringBuilder.append(digit);
            }
        }
        
        if (inLeadingZeros) {
            return &quot;0&quot;;
        }
        
        return stringBuilder.reverse().toString();
    }
    
    // Converts the integer digit to its textual hexadecimal representation:
    private static char toHexChar(int digit) {
        return digit &gt;= 0 &amp;&amp; digit &lt; 10 ? 
                (char)(digit + '0') :
                (char)(digit - 10 + 'a');
    }
    
    private static final int ITERATIONS = 10_000_000;
    private static final int WARMUP_ITERATIONS = 10_000_000;
    
    private static void warmup() {
        System.out.println(&quot;Warming up...&quot;);
        Random random = new Random();
        
        for (int i = 0; i &lt; WARMUP_ITERATIONS; i++) {
            int a = random.nextInt();
            intToHexString(a);
            Integer.toHexString(a);
        }
        
        System.out.println(&quot;Warming up done.&quot;);
    }
    
    private static void benchmark() {
        long seed = System.nanoTime();
        Random random = new Random(seed);
        System.out.println(&quot;Seed = &quot; + seed);
        
        int[] inputArray = new int[ITERATIONS];
        String[] outputArray1 = new String[inputArray.length];
        String[] outputArray2 = new String[inputArray.length];
        
        for (int i = 0; i &lt; inputArray.length; i++) {
            inputArray[i] = random.nextInt();
        }
        
        // Benchmarking intToHexString:
        long startTime = System.nanoTime();
        
        for (int i = 0; i &lt; ITERATIONS; i++) {
            outputArray1[i] = intToHexString(inputArray[i]);
        }
        
        long endTime = System.nanoTime();
        
        System.out.println(
                &quot;intToHexString in &quot; + 
                        ((endTime - startTime) / 1000_000) +
                        &quot; milliseconds.&quot;);
        
        // Benchmarking Integer.toHexString:
        startTime = System.nanoTime();
        
        for (int i = 0; i &lt; ITERATIONS; i++) {
            outputArray2[i] = Integer.toHexString(inputArray[i]);
        }
        
        endTime = System.nanoTime();
        
        System.out.println(
                &quot;Integer.toHexString in &quot; + 
                        ((endTime - startTime) / 1000_000) + 
                        &quot; milliseconds.&quot;);
        
        System.out.println(&quot;Methods agree: &quot; + Arrays.equals(outputArray1,
                                                             outputArray2));
    }
    
    public static void main(String[] args) {
        warmup();
        benchmark();
    }
}

Sample output

Warming up...
Warming up done.
Seed = 1290249323142300
intToHexString in 1041 milliseconds.
Integer.toHexString in 562 milliseconds.
Methods agree: true

Critique request
Please tell me anything that comes to mind.
inLeadingZeros I find dubious; wrong name probably
0x00_00_03_44 would be output as &quot;344&quot; whereas conventional would be a two-fold &quot;0344&quot; (or even interspaced as &quot;03 44&quot;). The reason that from left-to-right one can create a byte by two chars.
The exceptional case probably can be dealt with in front.
Error if (digit != 0) { should be if (digit != '0') { or something else is meant.
toHexChar still expects an int digit 0..10. So probably a semantic clash.
a as parameter name is unfortunate especially in English; num or n is more clear.

I am uncertain whether your code is correct by just reading it, due to the variable &amp; if.
/**
 * Converts the given integer into its textual hexadecimal representation.
 * 
 * @param num the integer to convert.
 * @return the string representing {@code num} in hexadecimal notation.
 */
public static String intToHexString(int num ) {
    if (num == 0) {
        return &quot;00&quot;;
    }
    
    StringBuilder stringBuilder = new StringBuilder(Integer.BYTES * 2);
    while (num != 0) {
        char digit = toHexChar(num &amp; 0xf);
        num &gt;&gt;&gt;= 4;
        stringBuilder.append(digit);

        digit = toHexChar(num &amp; 0xf);
        num &gt;&gt;&gt;= 4;
        stringBuilder.append(digit);
    }
    return stringBuilder.reverse().toString();
}

// Converts the integer digit to its textual hexadecimal representation:
private static char toHexChar(int digit) {
    return 0 &lt;= digit &amp;&amp; digit &lt; 10 ? 
            (char)(digit + '0') :
            (char)(digit - 10 + 'a');
}