Java - Write code to convert bytes To Hex String using & (and operator)

Requirements

Write code to bytes To Hex String

Demo

//package com.book2s;

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

    public static String bytesToHexString(byte[] src) {
        StringBuilder stringBuilder = new StringBuilder("");
        if (src == null || src.length <= 0) {
            return null;
        }
        for (int i = 0; i < src.length; i++) {
            int v = src[i] & 0xFF;
            String hv = Integer.toHexString(v);
            if (hv.length() < 2) {
                stringBuilder.append(0);
            }
            stringBuilder.append(hv);
        }
        return stringBuilder.toString();
    }
}