如何整个第二阵列添加到Java中第一个数组 [英] How to append entire second array to first array in java
问题描述
我知道,我们可以复制或追加数组的元素。但是,我有一个数组约100元。是否有任何其他方式提供,所以我可以追加数组第一个数组。
I know, We can copy or append elements of array. But, I have around 100 elements in an array. Is there any other way available so I can append array to first array.
考虑我有这样的两个数组。
Consider I have this two arrays.
String name1[]={"abc", "def", "ghi"};
String name2[]={"jkl", "mno", "pqr"};
我要NAME2数组中name1的末尾添加。
I want to append name2 array at the end of name1.
请帮我。
将是帮助表示感谢。
推荐答案
番石榴提供<一个href=\"http://docs.guava-libraries.google$c$c.com/git-history/release/javadoc/com/google/common/collect/ObjectArrays.html#concat%28T%5B%5D,%20T%5B%5D,%20java.lang.Class%29\"相对=nofollow> Arrays.concat(T [],T [],类&LT; T&GT;)
。
究其原因类
参数,仅供参考,是因为通用阵列具有明显的趋势得到上溯造型。如果你做了 Arrays.concat(整数[],长[])
,你想要一个对象[]
回?或号码[]
?番石榴让你指定所以没有含糊......因为所有的替代品可导致未predictable ClassCastException异常
在运行期。
The reason for the Class
parameter, FYI, is because generic arrays have a distinct tendency to get upcast. If you did Arrays.concat(Integer[], Long[])
, did you want an Object[]
back? Or a Number[]
? Guava makes you specify so there's no ambiguity...and because all of the alternatives can lead to unpredictable ClassCastException
s at runtime.
(披露:我对番石榴贡献)
(Disclosure: I contribute to Guava.)
这篇关于如何整个第二阵列添加到Java中第一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!