parse value to short - Android java.lang

Android examples for java.lang:String Parse

Description

parse value to short

Demo Code


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

public class Main {
    /**/*from   w  ww  .  j  av a  2 s . co m*/
     * parse value to short
     */
    public static short toShort(Object value) {
        if (value instanceof Number) {
            return ((Number) value).shortValue();
        }
        return value == null ? 0 : toShort(String.valueOf(value));
    }

    /**
     * parse value to short
     */
    public static short toShort(String value) {
        return TextUtils.isEmpty(value) ? 0 : Short.parseShort(value);
    }
}

Related Tutorials