Verify a string contains only numeric value in Java

The below example shows how to verify that a string contains only numeric values in Java. String may contain float value, double value etc. This example uses regular expression to check a string contains only numeric values. This method will not throw any exception.
Below is the method which validates a string contains only numeric values.

 

Below is the test method which gives the expected result from the above method.

 

Output

 

Thanks for reading. Please do not forget to leave a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.