### Question:
StringUtils { public static byte[] char2Byte(char[] a) { int len = 0; for (char c : a) { if (c > 0x7FF) { len += 3; } else if (c > 0x7F) { len += 2; } else { len++; } } byte[] result = new byte[len]; int i = 0; for (char c : a) { if (c > 0x7FF) { result[i++] = (byte) (((c >> 12) & 0x0F) | 0xE0); result[i++] = (byte) (((c >> 6) & 0x3F) | 0x80); result[i++] = (byte) ((c & 0x3F) | 0x80); } else if (c > 127) { result[i++] = (byte) (((c >> 6) & 0x1F) | 0xC0); result[i++] = (byte) ((c & 0x3F) | 0x80); } else { result[i++] = (byte) (c & 0x7F); } } return result; }  static boolean isCharEqual(char[] str); static boolean isNumeric(char[] str); static boolean isContains(char[] a, char[] b); static void clear(char[] a); static void clear(byte[] a); static byte[] char2Byte(char[] a); static char[] byte2Char(byte[] a); static void printOneByte(byte b); static byte[] hexs2Bytes(byte[] a);  }### Answer:
@Test public void char2Byte() { String asc = "test"; byte[] asc1 = asc.getBytes(UTF_8); byte[] asc2 = StringUtils.char2Byte(asc.toCharArray()); Assert.assertArrayEquals(asc1, asc2); }