- 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
Convert string to a number in Java
To convert a string to a number in Java, use the Integer.parseInt() method. First, let use create a String and set value.
String str = "45";
Now, take an Integer and use the Integer.parseInt() method.
Integer i = Integer.parseInt(str);
Let us see the complete example.
Example
public class Demo { public static void main( String args[] ) { String str = "45"; Integer i = Integer.parseInt(str); System.out.println("Num: " + i); } }
Output
Num: 45
Advertisements