try{ int num = Integer.parseInt(str); // is an integer! } catch (NumberFormatException e) { // not an integer! }