Java Integer Create toInteger(Object ob, Integer defaultInteger)

Here you can find the source of toInteger(Object ob, Integer defaultInteger)

Description

to Integer

License

Open Source License

Declaration

public static Integer toInteger(Object ob, Integer defaultInteger) 

Method Source Code

//package com.java2s;

public class Main {

    public static Integer toInteger(Object ob, Integer defaultInteger) {

        if (ob == null) {
            return defaultInteger;
        }/*from  w ww  .jav  a  2 s .  c o m*/

        if (ob instanceof Integer) {
            return ((Integer) ob).intValue();
        } else if (ob instanceof Float) {
            return ((Float) ob).intValue();
        } else if (ob instanceof Double) {
            return ((Double) ob).intValue();
        } else if (ob instanceof Byte) {
            return ((Byte) ob).intValue();
        } else {
            try {
                return new Integer(ob.toString());
            } catch (Exception e) {
                return defaultInteger;
            }
        }
    }

    public static Integer toInteger(Object ob) {
        return toInteger(ob, 0);
    }
}

Related

  1. toInteger(Object _value, int _default)
  2. toInteger(Object anObj)
  3. toInteger(Object cell)
  4. toInteger(Object o)
  5. toInteger(Object o)
  6. toInteger(Object obj)
  7. toInteger(Object obj)
  8. toInteger(Object obj)
  9. toInteger(Object object)