valueOf
The return is a wrapper class, the parameter can be String or this class
parse...
returns a basic type, and the parameter can only be String
When performing type conversion:
If you want to get the basic type, use parse...
it If you want to get the packaging type, usevalueOf
In addition, when obtaining the packaging type from the basic type, try to use valueOf
it instead of new
obtaining the packaging type, because valueOf
the cache is used.
public static Integer valueOf(int i) {
if (i >= IntegerCache.low && i <= IntegerCache.high)
return IntegerCache.cache[i + (-IntegerCache.low)];
return new Integer(i);
}
Reference:
https://blog.csdn.net/xiong9999/article/details/87800317