Java Byte Array Create toByteArray(char[] chars)

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

Description

to Byte Array

License

Apache License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static byte[] toByteArray(char[] chars) {
        byte[] bytes = new byte[chars.length];

        for (int i = 0; i != bytes.length; i++) {
            bytes[i] = (byte) chars[i];
        }//from  w  w  w.j a  v  a  2  s.  c om

        return bytes;
    }

    public static byte[] toByteArray(String string) {
        byte[] bytes = new byte[string.length()];

        for (int i = 0; i != bytes.length; i++) {
            char ch = string.charAt(i);

            bytes[i] = (byte) ch;
        }

        return bytes;
    }
}

Related

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