转换对象的数组,其基本类型的数组 [英] Converting an array of objects to an array of their primitive types

查看:132
本文介绍了转换对象的数组,其基本类型的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有有一个基本类型(例如字节,整型,字符等)的Java对象的数组。是否有一个整洁的方式,我可以把它转换成原始类型的数组?尤其是这可以无需通过创建内容的新数组和循环来完成。

If you have an array of Java objects which have a primitive type (for example Byte, Integer, Char, etc). Is there a neat way I can convert it into an array of the primitive type? In particular can this be done without having to create a new array and loop through the contents.

因此​​,例如,给定的

So for example, given

Integer[] array

什么是转换这个最巧妙的方式进入

what is the neatest way to convert this into

int[] intArray

不幸的是,这是我们必须相当频繁做Hibernate和超过我们无法控制一些第三方库接口连接时的东西。看来这将是一个相当常见的操作,所以我会感到惊讶,如果没有快捷方式。

Unfortunately, this is something we have to do quite frequently when interfacing between Hibernate and some third party libraries over which we have no control. It seems this would be a quite common operation so I would be surprised if there's no shortcut.

感谢您的帮助!

推荐答案

不幸的是,没有什么在Java平台做到这一点。顺便说一句,你还需要显式处理(即整数[] 阵列元素是什么 INT 你要使用那些?)。

Unfortunately, there's nothing in the Java platform that does this. Btw, you also need to explicitly handle null elements in the Integer[] array (what int are you going to use for those?).

这篇关于转换对象的数组,其基本类型的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆