Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.text.TextUtils;
import java.io.UnsupportedEncodingException;

public class Main {
    public static int getStringUTF8Length(final String str) {
        if (TextUtils.isEmpty(str)) {
            return 0;
        }

        try {
            return str.getBytes("UTF-8").length;
        } catch (final UnsupportedEncodingException e) {
            return 0;
        }
    }

    public static byte[] getBytes(final String s) {
        try {
            return s.getBytes("UTF-8");
        } catch (final UnsupportedEncodingException e) {
            return s.getBytes();
        }
    }
}