Here you can find the source of toShort(String value, short defaultValue)
Parameter | Description |
---|---|
value | string value |
defaultValue | default value |
static public short toShort(String value, short defaultValue)
//package com.java2s; //License from project: Open Source License public class Main { /**//from ww w . java 2 s . com * convert the string to an short, and return the default value if * the string is null or does not contain a valid int value * * @param value string value * @param defaultValue default value * * @return short */ static public short toShort(String value, short defaultValue) { if (value != null) { try { return Short.parseShort(value); } catch (NumberFormatException n) { } } return defaultValue; } /** * convert the string to an short, and return 0 if * the string is null or does not contain a valid int value * * @param value string value * * @return short */ static public short toShort(String value) { if (value != null) { try { return Short.parseShort(value); } catch (NumberFormatException n) { } } return 0; } }