如何整个第二阵列添加到Java中第一个数组 [英] How to append entire second array to first array in java

查看:126
本文介绍了如何整个第二阵列添加到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 ClassCastExceptions at runtime.

(披露:我对番石榴贡献)

(Disclosure: I contribute to Guava.)

这篇关于如何整个第二阵列添加到Java中第一个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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