Java Byte Array Create toByteArray(String str)

Here you can find the source of toByteArray(String str)

Description

Return a byte[] array from the string's chars, ANDed to the lowest 8 bits.

License

Open Source License

Parameter

Parameter Description
str a parameter

Declaration

public static final byte[] toByteArray(String str) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from w  w  w  .j  av  a  2s .c  om*/
     * Return a byte[] array from the string's chars,
     * ANDed to the lowest 8 bits.
     *
     * @param str
     * @return
     */
    public static final byte[] toByteArray(String str) {
        byte[] retour = new byte[str.length()];
        for (int i = 0; i < str.length(); i++) {
            retour[i] = (byte) (str.charAt(i) & 0xFF);
        }
        return retour;
    }
}

Related

  1. toByteArray(String hexString)
  2. toByteArray(String map)
  3. toByteArray(String s)
  4. toByteArray(String source)
  5. toByteArray(String str)
  6. toByteArray(String str)
  7. toByteArray(String str, String separator)
  8. toByteArray(String string)
  9. toByteArray(String string)