Here you can find the source of charsToBytes(char[] chars)
public static final byte[] charsToBytes(char[] chars)
//package com.java2s; //License from project: Open Source License public class Main { public static final byte[] charsToBytes(char[] chars) { byte[] b = new byte[chars.length << 1]; for (int i = 0; i < chars.length; i++) { char strChar = chars[i]; int bpos = i << 1; b[bpos] = (byte) ((strChar & 0xFF00) >> 8); b[bpos + 1] = (byte) (strChar & 0x00FF); }//from www .ja va 2 s .c o m return b; } }