Here you can find the source of charArrayToBytes(char[] chars)
public static byte[] charArrayToBytes(char[] chars)
//package com.java2s; public class Main { public static byte[] charArrayToBytes(char[] chars) { return charArrayToBytes(chars, chars.length); }//from ww w . j av a 2 s .c o m public static byte[] charArrayToBytes(char[] chars, int length) { byte[] bytes = new byte[length * 2]; for (int i = 0, j = 0; j < length; i += 2, j++) { int c = chars[j]; bytes[i] = (byte) (c >> 8); bytes[i + 1] = (byte) c; } return bytes; } }