Java - Write code to convert byte array To Hex String by converting each byte to hex string

Requirements

Write code to bytes To Hex String

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        byte[] argBytes = new byte[] { 34, 35, 36, 37, 37, 37, 67, 68, 69 };
        System.out.println(bytesToHexString(argBytes));
    }//from w w w .j a v a 2 s  . c  o m

    public static String bytesToHexString(final byte[] argBytes) {

        final StringBuffer buffer = new StringBuffer();
        for (int byteIndex = 0; byteIndex < argBytes.length; byteIndex++) {
            if (byteIndex != 0) {
                buffer.append(' ');
            }
            buffer.append(byteToHexString(argBytes[byteIndex]));
        }
        return buffer.toString();
    }

    public static String byteToHexString(final byte argByte) {
        int wrkValue = argByte;
        if (wrkValue < 0) {
            wrkValue += 0x100;
        }
        String result = Integer.toHexString(wrkValue);
        if (result.length() < 2) {
            result = "0" + result;
        }
        return result;
    }
}