Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static int toInt(String str, int defValue) { try { return Integer.parseInt(str); } catch (Exception e) { } return defValue; } public static int toInt(String str) { if (str == null) return 0; return toInt(str.toString(), 0); } }