Java Long Number Create toLong(Object obj)

Here you can find the source of toLong(Object obj)

Description

to Long

License

Open Source License

Declaration

public static long toLong(Object obj) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static long toLong(Object obj) {
        return toLong(obj, 0L);
    }//w  ww .j  ava 2  s .c  o m

    public static long toLong(Object obj, long defaultValue) {
        if (obj == null) {
            return defaultValue;
        }

        if (obj instanceof Number) {
            Number number = (Number) obj;
            return number.longValue();
        }
        String value = toString(obj);
        try {
            return Long.parseLong(value);
        } catch (Exception e) {
        }
        return defaultValue;
    }

    public static String toString(Object value) {
        if (value == null) {
            return "";
        }
        return value.toString().trim();
    }
}

Related

  1. toLong(Object obj)
  2. toLong(Object obj)
  3. toLong(Object obj)
  4. toLong(Object obj)
  5. toLong(Object obj)
  6. toLong(Object obj, String pattern)
  7. toLong(Object object)
  8. toLong(Object object)
  9. toLong(Object object)