English 中文(简体)
Google Collections equivalent to Apache Commons Collections ArrayUtils.toObject and ArrayUtils.toPrimitive
原标题:

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?

最佳回答

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.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签