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   w w w . ja v  a 2s. c  o m

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