Java String to convertString2Bytes(String str)

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

Description

convert String Bytes

License

Apache License

Declaration

public static byte[] convertString2Bytes(String str) 

Method Source Code

//package com.java2s;
/*/*from w  ww  . j  a  v a 2s  .  co  m*/
 *  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing,
 *  software distributed under the License is distributed on an
 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 *  KIND, either express or implied.  See the License for the
 *  specific language governing permissions and limitations
 *  under the License.
 *
 */

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

Related

  1. convertString(String label)
  2. convertString(String s)
  3. convertString(String s, Class cls)
  4. convertString(String strValue)
  5. convertString(String value, Class type)
  6. convertString2GSonString(String str)
  7. convertStringArrayToFloatArray(String[] num)
  8. convertStringArrayToString(String[] a_asStrings, String a_sDelim)
  9. convertStringArrayToString(String[] value, String separator)