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)));
    }//  w w w.  j a v a2s. c  o m
    public static byte[] str2byte(String str)
            throws UnsupportedEncodingException {
        return str.getBytes("UTF-8");
    }
}