There are many ways to do this task. exactly how depends on the type of
input stream you are reading. All of the classes that shadow Primitive
types (Integer, Boolean, Double, Long, etc) have a Foo.parse*(someString)
method which will converted someString to the type indicated by "*" where
Foo is the class name. Thus Integer.parseInt(someString) will return an int
value if the string can be converted. if not then it will throw a
NumberFormatException which you can catch. Nothing stops you from doing
character by character compares and there are methods of the char class
which can indicate with a boolean if a given character is a number or a
character. But I would recommend looking at the stringTokenizer class, and
the buffered read classes(for the type of stream you need to read). if you
are looking to validate data inputs, I would recommend you to leave the
character by character checking to the already built java classes.