Java Long Number Create toLong(Object value)

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

Description

to Long

License

Open Source License

Declaration

public static Long toLong(Object value) 

Method Source Code

//package com.java2s;
/*****************************************************************************
 * Copyright (c) 2015 Chris J Daly (github user cjdaly)
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w  w  w . j  av a  2  s  .c  o  m
 *   cjdaly - initial API and implementation
 ****************************************************************************/

public class Main {
    public static Long toLong(Object value) {
        if (value instanceof Long)
            return (Long) value;
        if (value instanceof Integer) {
            Integer v = (Integer) value;
            return v.longValue();
        }
        if (value instanceof String) {
            try {
                return Long.parseLong((String) value);
            } catch (NumberFormatException ex) {
                //
            }
        }
        return null;
    }
}

Related

  1. toLong(Object oid)
  2. toLong(Object property, long defaultValue)
  3. toLong(Object val)
  4. toLong(Object value)
  5. toLong(Object value)
  6. toLong(Object value)
  7. toLong(Object value)
  8. toLong(Object value)
  9. toLong(Object value)