Java - Write code to convert byte To Hex via String.format()

Requirements

Write code to byte To Hex

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        byte b = 42;
        System.out.println(byteToHex(b));
    }/*from  ww  w  . j  a  v a2s .c om*/

    public static String byteToHex(byte b) {
        return String.format("x%02X", b);
    }
}