I believe you have found an error in the API documentation. The best way to guarantee that you get a unique object is to use the
new operator.
The API
doc for Byte.toString() says:
public static String toString(byte b)
Returns a new String object representing the specified byte. The radix is assumed to be 10.
But, you will
not always get a new String object. This is the explanation:
Byte.toString() calls String.valueOf(int)
String.valueOf() calls Integer.toString(int,int) with the second argument = 10
Integer.toString(int,int) calls Integer.toString(int) when the second argument is 10
This is the code that is executed:
As you can see, 1 is a special case, always returning the String literal "1", which is in the string literal pool. 11 is the default case, returning a new String object each time.
You can consider the bug to be either in the code or in the API documentation. Perhaps
you should report it to Sun.