StringUtils { public static byte[] convertCharsToBytes(char[] chars) { byte[] result = new byte[chars.length*2]; for (int i=0; i<chars.length;i++) { result[2*i] = (byte) (chars[i] / 256); result[2*i+1] = (byte) (chars[i] % 256); } return result; } private  StringUtils(); static byte[] escapeString(final byte bytes[]); static void escapeString(final byte bytes[], final ByteBuffer content); static byte[] convertCharsToBytes(char[] chars);  }
@Test public void convertCharsToBytesTest() { byte[] check = {check1, check2}; char[] vals = {input}; byte[] result = StringUtils.convertCharsToBytes(vals); Assert.assertArrayEquals(check, result); }