Java tutorial
//package com.java2s; public class Main { public static long toLong(String s, long def) { if (s == null) { return def; } try { return Long.parseLong(s); } catch (NumberFormatException e) { return def; } } }