Here you can find the source of toByteArray(final char[] array)
public static byte[] toByteArray(final char[] array)
//package com.java2s; //License from project: Open Source License public class Main { public static byte[] toByteArray(final char[] array) { return toByteArray(array, 0, array.length); }/*from w w w. j a v a2 s. co m*/ public static byte[] toByteArray(final char[] array, final int off, final int len) { return toByteArray(array, off, len, new byte[len], 0); } public static byte[] toByteArray(final char[] from, final int fromOff, final int len, final byte[] to, final int toOff) { final int end = fromOff + len; for (int i = fromOff, j = toOff; i < end; i++, j++) { to[j] = (byte) from[i]; } return to; } public static byte[] toByteArray(final short[] array) { return toByteArray(array, 0, array.length); } public static byte[] toByteArray(final short[] array, final int off, final int len) { return toByteArray(array, off, len, new byte[len], 0); } public static byte[] toByteArray(final short[] from, final int fromOff, final int len, final byte[] to, final int toOff) { final int end = fromOff + len; for (int i = fromOff, j = toOff; i < end; i++, j++) { to[j] = (byte) from[i]; } return to; } public static byte[] toByteArray(final int[] array) { return toByteArray(array, 0, array.length); } public static byte[] toByteArray(final int[] array, final int off, final int len) { return toByteArray(array, off, len, new byte[len], 0); } public static byte[] toByteArray(final int[] from, final int fromOff, final int len, final byte[] to, final int toOff) { final int end = fromOff + len; for (int i = fromOff, j = toOff; i < end; i++, j++) { to[j] = (byte) from[i]; } return to; } public static byte[] toByteArray(final long[] array) { return toByteArray(array, 0, array.length); } public static byte[] toByteArray(final long[] array, final int off, final int len) { return toByteArray(array, off, len, new byte[len], 0); } public static byte[] toByteArray(final long[] from, final int fromOff, final int len, final byte[] to, final int toOff) { final int end = fromOff + len; for (int i = fromOff, j = toOff; i < end; i++, j++) { to[j] = (byte) from[i]; } return to; } public static byte[] toByteArray(final float[] array) { return toByteArray(array, 0, array.length); } public static byte[] toByteArray(final float[] array, final int off, final int len) { return toByteArray(array, off, len, new byte[len], 0); } public static byte[] toByteArray(final float[] from, final int fromOff, final int len, final byte[] to, final int toOff) { final int end = fromOff + len; for (int i = fromOff, j = toOff; i < end; i++, j++) { to[j] = (byte) from[i]; } return to; } public static byte[] toByteArray(final double[] array) { return toByteArray(array, 0, array.length); } public static byte[] toByteArray(final double[] array, final int off, final int len) { return toByteArray(array, off, len, new byte[len], 0); } public static byte[] toByteArray(final double[] from, final int fromOff, final int len, final byte[] to, final int toOff) { final int end = fromOff + len; for (int i = fromOff, j = toOff; i < end; i++, j++) { to[j] = (byte) from[i]; } return to; } }