Casting from string to int | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Casting from string to int

In Java language How can we cast an String to Integer ? For example : String a = "57" int b = 43 System.out.print(a+b); How can we convert variable a or its value to int so that we can output 100 ?

23rd Oct 2018, 3:04 AM
Googel
Googel - avatar
2 Answers
+ 1
Integer.parseInt(a) -> Integer
23rd Oct 2018, 3:09 AM
jtrh
jtrh - avatar
+ 2
I got it. I need to do: System.out.print(Integer.parseint(a)+b);
23rd Oct 2018, 3:14 AM
Googel
Googel - avatar