Here you can find the source of toByteArray(char[] chars)
public static byte[] toByteArray(char[] chars)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] toByteArray(char[] chars) { byte[] bytes = new byte[chars.length]; for (int i = 0; i != bytes.length; i++) { bytes[i] = (byte) chars[i]; }//from w w w.j a v a 2 s. c om return bytes; } public static byte[] toByteArray(String string) { byte[] bytes = new byte[string.length()]; for (int i = 0; i != bytes.length; i++) { char ch = string.charAt(i); bytes[i] = (byte) ch; } return bytes; } }