aspose file tools*
The moose likes Beginning Java and the fly likes check if is a number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "check if is a number" Watch "check if is a number" New topic
Author

check if is a number

Cathy Young
Ranch Hand

Joined: Mar 02, 2002
Posts: 126
Hi,
I have some strings and need to check if some of them are numbers. I am wondering if there is any existing API or implementation for this.
I thought of two ways to do it, but was not happy with either of them.
1. check the string character by character to see if it is a number. -- this is too boring and inefficient.
2. try Integer.parseInt (String) or Float.parseFloat (String) to see if NumberFormatException is thrown. I am worrying if there is any potential problem and it is too expensive to do this.
Any solutions or suggestions?
Thanks,
Cathy
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60077
    
  65

(2) is the way I do it.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Cathy Young
Ranch Hand

Joined: Mar 02, 2002
Posts: 126
Thanks, Bear!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: check if is a number
 
Similar Threads
looking for password check class
how to know the no of occurance in a string
HELP!!!!!
Using string.split with any delimiter
How to get or replace the backslash in Java string