Java Long Number Create toLong(Object ob, Long defaultLong)

Here you can find the source of toLong(Object ob, Long defaultLong)

Description

to Long

License

Open Source License

Declaration

public static Long toLong(Object ob, Long defaultLong) 

Method Source Code

//package com.java2s;

public class Main {

    public static Long toLong(Object ob, Long defaultLong) {

        if (ob == null) {
            return defaultLong;
        }//from   w w w.  j  a  va  2s.  co m

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

    public static Long toLong(Object ob) {
        return toLong(ob, 0l);
    }
}

Related

  1. toLong(Object num, long defValue)
  2. toLong(Object number)
  3. toLong(Object o)
  4. toLong(Object o)
  5. toLong(Object o)
  6. toLong(Object obj)
  7. toLong(Object obj)
  8. toLong(Object obj)
  9. toLong(Object obj)