Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me how I can able to convert string into a numbers in Java?

1 Answer

0 votes
by (26.7k points)

Basically, you can use Integer.parseInt function to convert the string into numbers, but we need to take care of NumberFormatException.

String myString = "1234";

int foo = Integer.parseInt(myString);

It will looks like this:

int foo;

try {

   foo = Integer.parseInt(myString);

}

catch (NumberFormatException e)

{

   foo = 0;

}

I hope this will help.

Want to become a Java expert? join Java Training now!!

Want to know more about Java? Watch this video on Java Tutorial for Beginners | Java programming:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...