- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to check if a string is a valid number
To check if a string is a valid Integer, use the Integer.parseInt() method, with the string to be checked passed as a parameter.
To check if a string is a valid Float, use the Float.parseFloat() method, with the string to be checked passed as a parameter.
The following is an example that checks for valid integer.
Example
public class Demo { public static void main(String args[]) throws Exception { String id = "100"; int val = Integer.parseInt(id); System.out.println(val); } }
Output
100
The following is an example that checks for valid float.
Example
public class Demo { public static void main(String args[]) throws Exception { String id = "100.5"; float val = Float.parseFloat(id); System.out.println(val); } }
Output
100.5
- Related Articles
- Check if a given string is a valid number in Python
- Check if a given string is a valid number in C++
- How to check if a string is a valid keyword in Java?
- Golang Program to Check if a string is a valid shuffle of two distinct strings
- Java Program to Check if a String is Numeric
- How to check if a string is a valid keyword in Python?
- How to check if a string is a valid keyword in C#?
- How to check if a string is a valid URL in Golang?
- C Program to check if a date is valid or not
- Python program to check if a given string is number Palindrome
- Program to check valid mobile number using Java regular expressions
- Java Program to check if a string is empty or not
- Java Program to Check if a String is Empty or Null
- Java Program to Check if a string contains a substring
- Java program to check if string is pangram

Advertisements