开发者

Java: Are there some quasi-standard APIs out there, which do int[] <-> Integer[] and similar?

I need to do lots of conversions between primitivetype[] and boxedtype[] (both directions).

Such as: Integer[] <-> int[], Double[] <-> double[], ...

I wanted to know, if there's some quasi-standar开发者_如何学Gods APIs out there, which provide such functionality, before I write such utility methods by myself.

Java has 8 primitive types, so it would be quite a (copy-paste) work...

Thank you.


ArrayUtils

ArrayUtils.toObject( primitive[] )

and

ArrayUtil.toPrimitive( wrapper[] )


Lately I've written a LGPL3 library, so it isn't stardard nor widely adopted, that try to addressing these problems:

Integer[] boxed = ... ;
int[] primitive = $(boxed).toIntArray();

and viceversa:

boxed = $(boxed).toArray();

But I'm hoping that you will appreciate some extra features like casting:

byte[] bytes = ...;
int[] ints = $(bytes).toIntArray();
short[] shorts = $(bytes).toShortArray();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜