How to test for an integer in Java

Java doesn’t have a tryParse method for integers. However, you can verify for an integer using the following method: public static boolean isInteger(String s) { try { Integer.parseInt(s); } catch(NumberFormatException e) { return false; } // only got here if we didn’t return false return true; }