Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Byte.decode("10") and Byte.valueOf("10") - what is a difference?

Tags:

java

wrapper

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");
like image 328
Nulldevice Avatar asked Dec 23 '22 06:12

Nulldevice


1 Answers

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.

like image 195
danben Avatar answered Jan 11 '23 09:01

danben