Java tutorial
//package com.java2s; public class Main { public static long convertTolong(String longStr, long defValue) { try { return Long.parseLong(longStr); } catch (NumberFormatException e) { } return defValue; } public static Long convertToLong(String longStr) { try { return Long.parseLong(longStr); } catch (NumberFormatException e) { } return null; } }