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?
views:
560answers:
1To 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.