Java Long Number Create toLong(Object o)

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

Description

to Long

License

Open Source License

Declaration

public static Long toLong(Object o) 

Method Source Code

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

public class Main {
    /**/*  www  . j  a  va 2  s.  co m*/
     *
     */
    public static Long toLong(Object o) {
        Long result;
        if (o == null) {
            result = null;
        } else if (o instanceof Number) {
            Number n = (Number) o;
            result = n.longValue();
        } else {
            try {
                result = Long.valueOf(o.toString().trim());
            } catch (Exception e) {
                throw new NumberFormatException("Invalid long: " + o);
            }
        }
        return result;
    }

    /**
     * Safely gets the Long equivalent of a Long value (and throws exception if no
     * such conversion is possible).
     */
    public static Long toLong(Long l) {
        if (l == null) {
            return null;
        } else {
            return l.longValue();
        }
    }
}

Related

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