如何在Java中添加两个一维数组 [英] How to add two arrays which are one dimension in java
本文介绍了如何在Java中添加两个一维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何添加数组.例如:A = {1,2,3} B = {5,6,7}结果数组应为c = {1,2,3,5,6,7};
怎么样?
请帮我
Thanks
How to add arrays . for ex: A= {1,2,3} B={5,6,7} resultant array should be c={1,2,3,5,6,7} ;
how ?
Plz help me
Thanks
推荐答案
检查Java数组是否具有"add"方法.如果不是,请创建一个合适大小的新数组,并在两个循环中复制两组值.
Check if the java arrays have an ''add'' method. If not, create a new array the right size and copy both sets of values in, in two loops.
您可以使用ArrayList
并添加带有addAll
的数组,然后执行toArray
及其结果以获取对象数组.
You can use aArrayList
and add the arrays withaddAll
then do atoArray
with the results to get an array of objects.
将数组转换为arrayList,然后添加两个arrayList并将它们转换回数组..
Convert array to arrayList , then add both arrayList and convert back them to array..
这篇关于如何在Java中添加两个一维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文