Check if string contains valid number example.
/* Check if string contains valid number example. This example shows how to check if string contains valid number or not using parseDouble and parseInteger methods of Double and Integer wrapper classes. */ public class CheckValidNumberExample { public static void main ( String [ ] args ) { String [ ] str = new String [ ] { "10.20" , "123456" , "12.invalid" } ; for ( int i = 0 ; i < str. length ; i ++ ) { if ( str [ i ] . indexOf ( "." ) > 0 ) { try { /* * To check if the number is valid decimal number, use * double parseDouble(String str) method of * Double wrapper class. * * This method throws NumberFormatException if the * argument string is not a valid decimal number. */ Double . parseDouble ( str [ i ] ) ; System . out . println ( str [ i ] + " is a valid decimal number" ) ; } ...