Closed GoogleCodeExporter closed 9 years ago
For join, Joiner works on object arrays. For indexOf, you can just do
Arrays.asList(array).indexOf(obj). Arrays.asList allows you to use most
collection APIs with arrays.
Original comment by cgdec...@gmail.com
on 24 Aug 2010 at 8:39
Makes sense, but then I wonder what the point of e.g. Ints.indexOf(int) is if
Ints.asList(int[]).indexOf(int) is just as good?
Original comment by eric.j...@gmail.com
on 24 Aug 2010 at 9:37
The indexOf method on the list returned by Ints.asList does seem to be
optimized to minimize boxing of values, but if you call it with an int, that
int is going to be boxed into an Integer and then unboxed again. No boxing will
happen with Ints.indexOf. The boxing issue won't exist with object arrays.
I'd say the main reason most of the methods in the primitives package exist is
that, unlike with objects, there are actual reasons to use arrays of primitives
rather than collections. For objects, collections should pretty much always be
used rather than arrays.
Original comment by cgdec...@gmail.com
on 24 Aug 2010 at 10:35
Thanks for the clarification.
Original comment by eric.j...@gmail.com
on 24 Aug 2010 at 10:39
cgdecker is right. We are averse to adding more support for Object arrays,
because they are so inferior to collections in so many ways it's ridiculous.
Unless you are a collection implementation yourself, you should probably never
use them.
Original comment by kevinb@google.com
on 8 Sep 2010 at 6:05
Amen kevinb! Maybe you can hit up Mr. Bloch to add this as an item in the 3rd
edition of Effective Java. Arrays are an implementation detail, and not
suitable for any public API.
Original comment by ray.j.gr...@gmail.com
on 13 Sep 2010 at 6:06
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
eric.j...@gmail.com
on 24 Aug 2010 at 6:43