parse value to byte - Android java.lang

Android examples for java.lang:String Parse

Description

parse value to byte

Demo Code


//package com.java2s;
import android.text.TextUtils;

public class Main {
    /**//w w w.ja  v  a2  s . c om
     * parse value to byte
     */
    public static byte toByte(Object value) {
        if (value instanceof Number) {
            return ((Number) value).byteValue();
        }
        return value == null ? 0 : toByte(String.valueOf(value));
    }

    /**
     * parse value to byte
     */
    public static byte toByte(String value) {
        return TextUtils.isEmpty(value) ? 0 : Byte.parseByte(value);
    }
}

Related Tutorials