Java 6 API primitive type wrappers have pairs of static methods decode(String s) and valueOf(String s). Both of them return a new object of wrapper class type and none of them are annotated as deprecated. Does someone know the difference between them? For example:
Byte b1 = Byte.decode("10");
and
Byte b2 = Byte.valueOf("10");
According to the documentation (http://java.sun.com/javase/6/docs/api/java/lang/Byte.html#valueOf%28java.lang.String%29), valueOf
only takes Strings that can be interpreted as signed decimal values, while decode
takes decimal, hex, or octal Strings (prefixed by 0x, #, or 0) - though valueOf
is overloaded to also take the radix explicitly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With