try { int i = Integer.parseInt(s); // s is a valid integer } catch (NumberFormatException e) { // s is not a valid integer }