+ 3

Can someone explain the difference between these two?

String numTest = "10"; Integer result1 = 10 + Integer.parseInt(numTest); Integer result2 = 10 + Integer.valueOf(numTest); System.out.println(result1); // outputs 20. System.out.println(result2); // outputs 20. what's the difference or secret behind them?

2nd Feb 2018, 4:27 PM
Moses Katsina
Moses Katsina - avatar
2 Answers
+ 18
there is difference in there return type 1)Integer.valueOf (String) returns Integer object 2)Integer.parseInt (String) returns primitive Integer type (int)
2nd Feb 2018, 5:24 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 1
now I get it😃. thanks
2nd Feb 2018, 9:05 PM
Moses Katsina
Moses Katsina - avatar