Java - Write code to convert string to byte array with UTF-8

Requirements

Write code to convert string to byte array with UTF-8

Demo

import java.io.UnsupportedEncodingException;

public class Main{
    public static void main(String[] argv){
        String str = "book2s.com";
        System.out.println(java.util.Arrays.toString(str2byte(str)));
    }/*  www.jav a  2s .c om*/
    public static byte[] str2byte(String str)
            throws UnsupportedEncodingException {
        return str.getBytes("UTF-8");
    }
}