Java Byte Array Create toByteArray(String str)

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

Description

to Byte Array

License

Open Source License

Declaration

private static byte[] toByteArray(String str) 

Method Source Code

//package com.java2s;
/*// w w w. j  a va  2  s.c o  m
 * Copyright (C) 2006-2007 Mindquarry GmbH, All Rights Reserved
 * 
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 */

public class Main {
    private static byte[] toByteArray(String str) {
        byte[] result = new byte[str.length() + 1];
        for (int i = 0; i < str.length(); i++) {
            result[i] = (byte) str.charAt(i);
        }
        result[str.length()] = 0;
        return result;
    }
}

Related

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