Java examples for java.lang:String Parse
Parse string to short, return defaultValue if parse fails
public class Main{ /** Parse string to short, return defaultValue if parse fails */ public static short parseShort(String value, short defaultValue) { short parsed = defaultValue; if (value != null) { try { parsed = Short.parseShort(value); } catch (NumberFormatException e) { parsed = defaultValue;/* ww w. j ava2 s. co m*/ } } return parsed; } }