Java Utililty Methods String Parse

List of utility methods to do String Parse

Description

The list of methods to do String Parse are organized into topic(s).

Method

ObjecttryParse(String input, Object defVal)
try Parse
if (input.equals("null"))
    return defVal;
if (defVal instanceof Boolean) {
    return Boolean.valueOf(input);
} else {
    if (input.equals("true"))
        return true;
    if (input.equals("false"))
...
booleantryParse(String pValue)
Seriously..
try {
    Integer.parseInt(pValue);
    return true;
} catch (NumberFormatException nfe) {
    return false;
doubletryParse(String s, double d)
try Parse
try {
    return Double.parseDouble(s);
} catch (Exception e) {
    return d;
inttryParse(String s, int i)
try Parse
try {
    return Integer.parseInt(s);
} catch (Exception e) {
    return i;
IntegertryParse(String s, Integer defaultValue)
try Parse
try {
    return Integer.parseInt(s);
} catch (Exception e) {
    return defaultValue;
inttryParse(String val, int defaultValue)
try Parse
int v = defaultValue;
try {
    v = Integer.parseInt(val);
} catch (Exception e) {
return v;
ObjecttryParseToType(Object object, Class clazz)
try Parse To Type
try {
    return clazz.getConstructor(new Class[] { String.class }).newInstance(object.toString());
} catch (Exception e) {
    return object;
booleanTryParseUShort(String str, short[] u)
Try Parse U Short
return TryParseShort(str, u);