Convert string to UTF8 string - Android java.lang

Android examples for java.lang:String UTF-8

Description

Convert string to UTF8 string

Demo Code

import android.text.TextUtils;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.util.AbstractCollection;
import java.util.Collection;
import java.util.Iterator;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static String toUtf8(String str) {
        try {/*from  w  ww .  j  a  va2s. c  om*/
            byte[] strb = null;
            strb = str.getBytes("UTF-8");
            String newStr = new String(strb);
            return newStr;
        } catch (UnsupportedEncodingException e) {
            return str;
        }
    }

}

Related Tutorials