Rabu, 28 Juli 2021

Difference between valueOf and parseInt method in Java? Example

Both valueOf and parseInt methods are used to convert String to Integer in Java, but there is subtle differences between them. If you look at the code of valueOf() method, you will find that internally it calls parseInt() method to convert String to Integer, but it also maintains a pool of Integers from -128 to 127 and if the requested integer is in the pool, it returns an object from the pool. This means two integer objects returned using the valueOf() method can be the same by the equality operator. This caching of Immutable object, does help in reducing garbage and help garbage collectors. 

Lorem ipsum is simply dummy text of the printing and typesetting industry.

Comments


EmoticonEmoticon