Since everyone praises Google Collections (e.g. in here)
How come I can't find the equivalent of ArrayUtils.toObject()
and ArrayUtils.toPrimitive()
? is it that unusable? did I miss it?

- 1
- 1

- 44,555
- 61
- 184
- 276
-
1Google Collections is far less mature than Commons Collections, it just doesn't have the same quantity and breadth of utility methods. – skaffman Dec 30 '09 at 12:23
-
6I'd digress, Google Collections is quite mature, however it is built in a professional way in which it handles only collection related things (since those are the library's responsibility) and leaves general purpose things for other libraries. That's actually my major gripe with most Commons libraries at the moment, they do a lot of useful things but also things which do not belong to that one particular library at all but some other one instead. – Esko Dec 30 '09 at 12:46
-
Oh, as for maturity goes, Google Collections just hit 1.0 final :) – Esko Dec 31 '09 at 08:45
1 Answers
To be honest I'm not sure if either of those methods should even qualify as a collection-related operation and as such I'd wonder why they're even there in the first place.
To clarify a bit, collections are generically a group of objects with some semantic data binding them together while arrays are just a predetermined set of something. This semantic data may be information about accepting or rejecting nulls, duplicates, objects of wrong types or with unacceptable field values etc.
Most -if not all- collections do use arrays internally, however array itself isn't a collection. To qualify as a collection it needs some relevant magic such as removing and adding objects to arbitrary positions and arrays can't do that. I very much doubt you'll ever see any kind of array support in Google Collections since arrays are not collections.
However since Google Collections is going to be part of Google's Guava libraries which is a general purpose utility class library/framework of sorts, you may find what you want from com.google.common.primitives
package, for example Booleans#asList(boolean... backingArray)
and Booleans#toArray(Collection<Boolean> collection)
.
If you absolutely feel they should include equal methods to Apache Commons Collection's .toObject()
and .toPrimitive()
in there, you can always submit a feature request as new issue.

- 29,022
- 11
- 55
- 82
-
So you say ArrayUtils should have been in common-lang? I can agree with that, but most less keen programmers will still have looked in common-collections first... (yes, for some of us array is a collection) though I agree with the philosophical point of view – Eran Medan Dec 30 '09 at 12:47
-
Yeah. I know it's confusing if you're not really into collections and official definitions, but since I know Google's workers are into those things, I'd suspect that's why they've left array related operations (*mostly?*) out from Google Collections. – Esko Dec 30 '09 at 12:51
-
+1 from me as well, indeed, a very good answer, didn't expect it so quickly – Eran Medan Dec 30 '09 at 13:09
-
1You got lucky with my "code compiling" (actually "graphics artist is making the final touches to layout code") moment :) – Esko Dec 30 '09 at 13:13
-
3Thanks Esko for this great answer! Amusingly, we do have an ObjectArrays utility class in Google Collections, despite the true fact that arrays aren't collections. But still, the collections package has nothing primitives-related -- you have the correct references for those things. – Kevin Bourrillion Dec 30 '09 at 22:06