Java Long Number Create toLong(String str)

Here you can find the source of toLong(String str)

Description

to Long

License

Open Source License

Declaration

public static long toLong(String str) 

Method Source Code

//package com.java2s;
/**//  ww  w  .  jav  a 2s  . c  o m
 * KTH Developed by Java
 *
 * @Copyright 2011 by Service Platform Development Team, KTH, Inc. All rights reserved.
 *
 * This software is the confidential and proprietary information of KTH, Inc.
 * You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with KTH.
 */

public class Main {
    public static long toLong(String str) {
        return toLong(str, 0L);
    }

    public static long toLong(String str, long defaultValue) {
        if (str == null) {
            return defaultValue;
        }
        try {
            return Long.parseLong(str);
        } catch (Exception e) {
            return defaultValue;
        }
    }

    public static long toLong(Object obj) {
        return toLong(obj, 0L);
    }

    public static long toLong(Object obj, long defaultValue) {
        if (obj == null) {
            return defaultValue;
        }
        try {
            return (Long) obj;
        } catch (Exception nfe) {
            return defaultValue;
        }
    }
}

Related

  1. toLong(String s)
  2. toLong(String s)
  3. ToLong(String s)
  4. toLong(String s, long defValue)
  5. toLong(String src)
  6. toLong(String str)
  7. toLong(String str)
  8. toLong(String str)
  9. toLong(String str)