Java Utililty Methods Short Number Create

List of utility methods to do Short Number Create

Description

The list of methods to do Short Number Create are organized into topic(s).

Method

ShorttoShort(Object obj)
to Short
return obj == null ? null : obj instanceof Short ? (Short) obj : newShort(obj);
shorttoShort(Object prmIntObject)
to Short
short rtnInt16 = 0;
if (prmIntObject != null) {
    if (prmIntObject.toString() != "") {
        rtnInt16 = Short.parseShort(prmIntObject.toString());
return rtnInt16;
ShorttoShort(Object value)
Convert an Object to a Short.
if (value == null)
    return null;
if (value instanceof Short)
    return (Short) value;
if (value instanceof String) {
    if ("".equals((String) value))
        return null;
    return new Short((String) value);
...
shorttoShort(Object value)
To short.
return Short.parseShort(value.toString());
ShorttoShort(Object value)
to Short
try {
    if (value == null || EMPTY.equals(value)) {
        return null;
    return Short.valueOf(value.toString());
} catch (Exception e) {
    e.printStackTrace();
    return null;
...
shorttoShort(Object value)
to Short
if (value instanceof Number)
    return ((Number) value).shortValue();
else if (value == null)
    return 0;
else
    return Short.parseShort(value.toString());
longtoShort(Object value)
to Short
return (value == null || "null".equals(value.toString())) ? 0 : Short.parseShort(value.toString().trim());
shorttoShort(String input, short defaultValue)
to Short
try {
    return Short.parseShort(input);
} catch (Exception e) {
    return defaultValue;
shorttoShort(String numeric)
to Short
return (isNumeric(numeric)) ? Short.parseShort(numeric) : 0;
shorttoShort(String str)

Convert a String to a short, returning zero if the conversion fails.

If the string is null, zero is returned.

 NumberUtils.toShort(null) = 0 NumberUtils.toShort("")   = 0 NumberUtils.toShort("1")  = 1 
return toShort(str, (short) 0);