Validate if string is a number
public class Main { public static boolean checkIfNumber(String in) { try { Integer.parseInt(in); } catch (NumberFormatException ex) { return false; } return true; } public static void main(String[] args) { System.out.println(checkIfNumber("ABC")); System.out.println(checkIfNumber("123123123123123")); } }