Question: how to check if a string contains only numeric digits in java?
Answer: To check if string contains numbers only, in the try block, we use Double 's parseDouble() method to convert the string to a Double . If it throws an error (i.e. NumberFormatException error), it means string isn't a number and numeric is set to false . Else, it's a number.