Java Null Value Convert null2Int(Object object, int def)

Here you can find the source of null2Int(Object object, int def)

Description

null Int

License

Apache License

Declaration

public static int null2Int(Object object, int def) 

Method Source Code

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

public class Main {

    public static int null2Int(Object s) {
        return null2Int(s, -1);
    }// w w  w .  j  a v  a2  s .  c  o  m

    public static int null2Int(Object object, int def) {

        if (object != null) {
            try {
                return Integer.parseInt(object.toString());
            } catch (Exception e) {
            }
        }
        return def;
    }
}

Related

  1. null2Double(Object s, double defValue)
  2. null2Empty(Object obj)
  3. null2empty(Object s)
  4. null2empty(String str)
  5. null2emptyString(String value)
  6. null2Length0(String s)
  7. null2NA(String str)
  8. Null2Space(String str)
  9. null2Str(Object obj)