convert string To byte array in Unicode - Android java.lang

Android examples for java.lang:Byte Array

Description

convert string To byte array in Unicode

Demo Code

import java.io.UnsupportedEncodingException;

public class Main{

    public static byte[] convertToUnicode(String str) {
        byte[] result = null;
        try {/*from  w w w .  jav  a 2  s. c  om*/
            byte[] res = str.getBytes("utf-8");
            result = new byte[res.length + 1];
            for (int i = 0; i < res.length; i++) {
                result[i] = res[i];
            }
        } catch (UnsupportedEncodingException localUnsupportedEncodingException) {
        }
        return result;
    }

}

Related Tutorials