Try executing Integer.parseInt(yourString) , and if he chooses a NumberFormatException , you will find out that the string is not a valid integer
try { Integer.parseInt(myString); System.out.println("An integer"): } catch (NumberFormatException e) {
Another alternative is regex:
boolean isInteger = Pattern.matches("^\d*$", myString);
source share