safe Parse Long - Java java.lang

Java examples for java.lang:String Parse

Description

safe Parse Long

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        String toParse = "java2s.com";
        System.out.println(safeParseLong(toParse));
    }/*  ww w  .  j a  v  a  2  s  . c  o m*/

    public static Long safeParseLong(String toParse) {
        try {
            return Long.valueOf(toParse);
        } catch (NumberFormatException e) {
            return null;
        }
    }
}

Related Tutorials