Java Byte Array Create toByteArray(char[] chars)

Here you can find the source of toByteArray(char[] chars)

Description

Convert the given char array into a byte array.

License

Open Source License

Parameter

Parameter Description
chars the char array

Return

the converted array

Declaration

public static byte[] toByteArray(char[] chars) 

Method Source Code

//package com.java2s;

public class Main {
    /**//ww  w. j  a va2s.  c o m
     * Convert the given char array into a byte array.
     *
     * @param chars the char array
     * @return the converted array
     */
    public static byte[] toByteArray(char[] chars) {
        byte[] result = new byte[chars.length];
        for (int i = chars.length - 1; i >= 0; i--) {
            result[i] = (byte) chars[i];
        }
        return result;
    }
}

Related

  1. toByteArray(byte num)
  2. toByteArray(byte value)
  3. toByteArray(char c)
  4. toByteArray(char[] charArray)
  5. toByteArray(char[] chars)
  6. toByteArray(char[] src)
  7. toByteArray(CharSequence hexString)
  8. toByteArray(double[][] array)
  9. toByteArray(final byte[] bytes)