问题描述
有没有办法将整数列表转换为整数数组(不是整数)。像List to int []之类的东西?没有循环遍历列表并手动将intger转换为int。
Is there a way, to convert a List of Integers to Array of ints (not integer). Something like List to int []? Without looping through the list and manually converting the intger to int.
推荐答案
我相信你可以在第三方找到一些东西 - 派对库,但我不相信Java标准库中内置了任何内容。
I'm sure you can find something in a third-party library, but I don't believe there's anything built into the Java standard libraries.
我建议您只编写一个实用程序函数来执行此操作,除非您需要大量的类似的功能(在这种情况下,值得找到相关的第三方库)。请注意,您需要弄清楚如何处理列表中的空引用,这显然无法在int数组中准确表示。
I suggest you just write a utility function to do it, unless you need lots of similar functionality (in which case it would be worth finding the relevant 3rd party library). Note that you'll need to work out what to do with a null reference in the list, which clearly can't be represented accurately in the int array.
这篇关于将整数列表转换为int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!