Here you can find the source of toByteArray(char[] src)
public static byte[] toByteArray(char[] src)
//package com.java2s; // The MIT License (MIT) public class Main { public static byte[] toByteArray(char[] src) { byte[] arr = new byte[src.length * 2]; for (int i = 0; i < src.length; i++) { char chr = src[i]; arr[i * 2] = (byte) (0xff & (chr >> 8)); arr[i * 2 + 1] = (byte) (0xff & (chr)); }//from w w w.j av a 2 s .c om return arr; } }