Tim is right. However, should you choose to rely on it, using replaceAll is a bad idea. That will not only remove the first and last , but also any occurrence within the String. Better is to just cut off the first and last character, which will also be faster:
Tim Moores wrote:The latter depends on assumptions about the internal workings of the List.toString method - those are not documented and could change from release to release. Thus, you should not rely on it.
Actually, they are - in AbstractCollection - which pretty much any List (including the one produced by Arrays.asList()) will implement.
That said, I totally agree with your general statement.
@Robin: Personally, I'd pick option 1, for the simple reason that you don't want the format produced by Arrays.asList().toString(). I'd also be very surprised if the difference in time is noticeable.
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here