Java String Parse tryParse(String s, Integer defaultValue)

Here you can find the source of tryParse(String s, Integer defaultValue)

Description

try Parse

License

Open Source License

Declaration

public static Integer tryParse(String s, Integer defaultValue) 

Method Source Code

//package com.java2s;

public class Main {
    public static Integer tryParse(String s, Integer defaultValue) {
        try {/*from   ww  w. j a  va2s.c  o  m*/
            return Integer.parseInt(s);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public static Integer tryParse(String text, int maxLow, int maxHigh) {
        Integer i = tryParse(text, null);
        if (i == null || i < maxLow || i > maxHigh) {
            i = null;
        }
        return i;
    }
}

Related

  1. tryParse(String input, Object defVal)
  2. tryParse(String pValue)
  3. tryParse(String s, double d)
  4. tryParse(String s, int i)
  5. tryParse(String val, int defaultValue)
  6. tryParseToType(Object object, Class clazz)
  7. TryParseUShort(String str, short[] u)