This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Given a String, is there a way to make sure that it's a valid real number, containing only the digits 0 - 9 and has no more than one decimal point? Would attempting a cast and catching an exception work or is there a better way?
You could use valueOf(), pass the string to it. If it ain't a number that will fit within the wrapper object you're using, it will throw a NumberFormatException. If you wanted, you could use a bunch of if statements or something like that, but I would imagine the best way would be using a try/catch( NumberFormatException e ) block [This message has been edited by jason adam (edited August 16, 2001).]