Is there a quick way to check for a String containing numerics? Rather than going through each individual number (0 - 9) and seeing if it's contained within the String, I'd like to be able to return a true or false with one check for whether numerics are contained ot not. Thanks!
Paul Stevens
Ranch Hand
Joined: May 17, 2001
Posts: 2823
posted
0
Integer.parseInt(string) will throw a NumberFormatException if not all numbers so just catch and return false else return true.
Peter den Haan
author
Ranch Hand
Joined: Apr 20, 2000
Posts: 3252
posted
0
I assume that you want to know if the string contains any numbers, and not just (as assumed by the previous respondent) if it is a valid number. Java 1.4 will have a regular expression library in the platform (YES! ). In the mean time, you could use the one from the Apache project - Oro. However, if all you want is something quick and dirtyThis should do the job (haven't tested it though). Sufficiently fast for most purposes and just a single line of code. However, I would suggest leaving it in a method of its own as shown above as it functionality is not immediately obvious. - Peter
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.