Friday, 24 April 2020

SE - 67 - Difference between valueOf and parseInt !

INTEGER.PARSEINT()INTEGER.VALUEOF()
It can only take a String as a parameter.It can take a String as well as an integer as parameter.
It returns a primitive int value.It returns an Integer object.
When an integer is passed as parameter, it produces an error due to incompatible typesWhen an integer is passed as parameter, it returns an Integer object corresponding to the given parameter.
This method produces an error(incompatible types) when a character is passed as parameter.This method can take a character as parameter and will return the corresponding unicode.
This lags behind in terms of performance since parsing a string takes a lot of time when compared to generating one.This method is likely to yield significantly better space and time performance by caching frequently requested values.
If we need the primitive int datatype then Integer.parseInt() method is to be used.If Wrapper Integer object is needed then valueOf() method is to be used.

No comments:

Post a Comment