What is the difference between parseInt and valueOf? I think parseFloat(), parseDouble(), parseLong() are the same... What's the difference between this and Long.valueOf(string)?
Which one is more commonly used?
java language-feature
If you look at the API... Integer.valueOf(String) is interpreted exactly as String did Integer.parseInt(String). However, valueOf(String) returns the object to newInteger() and parseInt(String) returns the int default datatype.
If you want to write some efficient code with Integer.valueOf(int), you need to write an eye-catching code like below.
Integer k = Integer.valueOf(Integer.parseInt("123"))
In conclusion, when converting a string, you can use valueOf(String) if you want to receive it as an object other than the basic data type. If not, use parseInt(String).
© 2024 OneMinuteCode. All rights reserved.