How to convert numeric String to int in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 13

How to convert numeric String to int in java

19th Jan 2022, 5:38 AM
😇🌟SWATI🌟😇
😇🌟SWATI🌟😇 - avatar
7 Answers
+ 8
convert String to an int in java using Integer.parseInt() method. To convert String into Integer, we can use Integer.valueOf() method which returns instance of Integer class.
4th Feb 2022, 3:07 AM
😇🌟SWATI🌟😇
😇🌟SWATI🌟😇 - avatar
+ 14
String str=”0111”; int t=Integer.parseInt(str); System.out.println(t); Integer x = Integer.valueOf(str); // or int y = Integer.parseInt(str);
19th Jan 2022, 12:29 PM
Vaibhav
Vaibhav - avatar
+ 5
Use Integer.parseInt(stringRepr); if you need a primitive int. Use Integer.valueOf(stringRepr); if you need an Integer object.
19th Jan 2022, 6:04 AM
Ani Jona 🕊
Ani Jona 🕊 - avatar
+ 5
Ipang thank you 😊
19th Jan 2022, 6:06 AM
😇🌟SWATI🌟😇
😇🌟SWATI🌟😇 - avatar
+ 4
String str=”0111”; int t=Integer.parseInt(str); System.out.println(t); Integer x = Integer.valueOf(str); int y = Integer.parseInt(str); The sbove is two ways to convert from string to int First way is a wrapperclass used to convert from primitive to object or object to primitive Next way is an alternate method to convert to int If we want to convert to string again For that String.valueOf() can convert back to string data
20th Jan 2022, 6:48 PM
sree harsha
sree harsha - avatar
+ 2
use typecasting
2nd Feb 2022, 11:18 AM
CLIFFORD MUKOSH