Java difference between Short.parseShort and Short.valueOf -


this question has answer here:

i have stumbled upon another question on stack overflow 1 person suggests using short.parseshort(string s) , short.valueof(string s).

i have tried both myself, , found no difference in functionality , official documentation didn't me either:

short.parseshort: parses string argument signed decimal short. characters in string must decimal digits, except first character may ascii minus sign '-' ('\u002d') indicate negative value or ascii plus sign '+' ('\u002b') indicate positive value. resulting short value returned, if argument , radix 10 given arguments parseshort(java.lang.string, int) method.

short.valueof: returns short object holding value given specified string. argument interpreted representing signed decimal short, if argument given parseshort(java.lang.string) method. result short object represents short value specified string.

both accept additional parameter radix, , both throw numberformatexception.

they seem identical, if case, why both exist?

valueof using parseshort internally , additionally wraps value in boxed type short:

public static short valueof(string s, int radix)     throws numberformatexception {     return valueof(parseshort(s, radix)); } 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

.htaccess - ERR_TOO_MANY_REDIRECTS htaccess -