Java Integer Parse tryParseInt(Object obj, Integer defaultVal)

Here you can find the source of tryParseInt(Object obj, Integer defaultVal)

Description

try Parse Int

License

Apache License

Declaration

public static Integer tryParseInt(Object obj, Integer defaultVal) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static Integer tryParseInt(Object obj, Integer defaultVal) {
        if (obj == null)
            return defaultVal;
        if (obj instanceof Integer)
            return (Integer) obj;
        try {//  w  w  w  .  ja  va2  s  .c  om
            String val = obj.toString();
            return Integer.parseInt(val);
        } catch (Exception e) {
            return defaultVal;
        }
    }
}

Related

  1. tryParseInt(Object o)
  2. tryParseInt(String intString, int defaultValue)
  3. tryParseInt(String num)
  4. tryParseInt(String s)
  5. tryParseInt(String str)