Parse Long from String with default value - Java java.lang

Java examples for java.lang:String Parse

Description

Parse Long from String with default value

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String value = "java2s.com";
        System.out.println(getLong(value));
    }// w w w  .  j a v a  2 s . co m

    public static Long getLong(String value, Long defaultValue) {
        try {
            return Long.valueOf(value);
        } catch (Exception ex) {
            return defaultValue;
        }
    }

    public static Long getLong(String value) {
        return getLong(value, null);
    }
}

Related Tutorials