Java Char Array to Byte Array charsToBytes(char[] in)

Here you can find the source of charsToBytes(char[] in)

Description

Note: only one-byte symbols are supported.

License

Open Source License

Declaration

public static byte[] charsToBytes(char[] in) 

Method Source Code

//package com.java2s;
/*//from w  w  w.j ava 2 s.  c om
 * This program is free software: you can redistribute it and/or modify it 
 * under the terms of the GNU General Public License as published by 
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 */

public class Main {
    /**
     *   Note:   only one-byte symbols are supported.
     */
    public static byte[] charsToBytes(char[] in) {
        int size = in.length;
        byte[] out = new byte[size];

        for (int i = 0; i < size; i++) {
            out[i] = (in[i] < 256) ? (byte) in[i] : 63 /* ? */;
        }

        return out;
    }
}

Related

  1. charArrayToBytes(char[] chars)
  2. chars2Bytes(char[] chars)
  3. chars2Bytes(char[] chars)
  4. charsToBytes(char[] chars)
  5. charsToBytes(char[] chars)
  6. charsToBytes(final char[] chars, final int charOffset, final int length, final byte[] bytes, final int byteOffset)
  7. ConvertCharArrayToByteArray(char value[])
  8. convertCharsToBytes(char[] chars)
  9. convertCharsToBytes(char[] chars)