Java tutorial
//package com.java2s; public class Main { public static int toInteger(String number, String pre) { int newNumber = 0; if (isNumber(number)) { newNumber = Integer.parseInt(number); } else { newNumber = Integer.parseInt(pre); } return newNumber; } public static boolean isNumber(String string) { try { Long.parseLong(string); } catch (Exception e) { return false; } return true; } }