Converting A String To Hexadecimal In Java

Here’s a short way to convert it to hex:

public String toHex(String arg) {
    return String.format("%040x", new BigInteger(1, arg.getBytes(/*YOUR_CHARSET?*/)));
}

Leave a Comment