JAVA怎么合并两个数组
4个回答
展开全部
三种字符数组合并的方法
public static String[] getOneArray() {
String[] a = { "0", "1", "2" };
String[] b = { "0", "1", "2" };
String[] c = new String[a.length + b.length];
for (int j = 0; j < a.length; ++j) {
c[j] = a[j];
}
for (int j = 0; j < b.length; ++j) {
c[a.length + j] = b[j];
}
return c;
}
public static Object[] getTwoArray() {
String[] a = { "0", "1", "2" };
String[] b = { "0", "1", "2" };
List aL = Arrays.asList(a);
List bL = Arrays.asList(b);
List resultList = new ArrayList();
resultList.addAll(aL);
resultList.addAll(bL);
Object[] result = resultList.toArray();
return result;
}
public static String[] getThreeArray() {
String[] a = { "0", "1", "2", "3" };
String[] b = { "4", "5", "6", "7", "8" };
String[] c = new String[a.length + b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);
return c;
}
Reference: http://www.cnblogs.com/changhongzhi/articles/2242323.html
展开全部
int a[]={12,23,15,11,56,51};
int b[]={4,2,50,78,90};
ArrayList<Integer> alist=new ArrayList<Integer>(a.length+b.length);
for (int j = 0; j < a.length; j++) {
alist.add(a[j]);
}
for (int k = 0; k < b.length; k++) {
alist.add(b[k]);
}
int c[] =new int[alist.size()];
for(int i=0; i<alist.size();i++){
c[i]=alist.get(i);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐于2017-09-27
展开全部
java数组合并问题
三种字符数组合并的方法
public static String[] getOneArray() {
String[] a = { "0", "1", "2" };
String[] b = { "0", "1", "2" };
String[] c = new String[a.length + b.length];
for (int j = 0; j < a.length; ++j) {
c[j] = a[j];
}
for (int j = 0; j < b.length; ++j) {
c[a.length + j] = b[j];
}
return c;
}
public static Object[] getTwoArray() {
String[] a = { "0", "1", "2" };
String[] b = { "0", "1", "2" };
List aL = Arrays.asList(a);
List bL = Arrays.asList(b);
List resultList = new ArrayList();
resultList.addAll(aL);
resultList.addAll(bL);
Object[] result = resultList.toArray();
return result;
}
public static String[] getThreeArray() {
String[] a = { "0", "1", "2", "3" };
String[] b = { "4", "5", "6", "7", "8" };
String[] c = new String[a.length + b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);
return c;
}
1.两个字符数组合并的问题
public String[] getMergeArray(String[] al,String[] bl) {
String[] a = al;
String[] b = bl;
String[] c = new String[a.length + b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);
return c;
}
2.字符数组和整形数组合并问题
public int[] getIntArray(int[] al,String[] bl) {
int[] a = al;
String[] b = bl;
int[] ia=new int[b.length];
for(int i=0;i<b.length;i++){
ia[i]=Integer.parseInt(b[i]);
}
int[] c = new int[a.length + ia.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(ia, 0, c, a.length, ia.length);
return c;
}
三种字符数组合并的方法
public static String[] getOneArray() {
String[] a = { "0", "1", "2" };
String[] b = { "0", "1", "2" };
String[] c = new String[a.length + b.length];
for (int j = 0; j < a.length; ++j) {
c[j] = a[j];
}
for (int j = 0; j < b.length; ++j) {
c[a.length + j] = b[j];
}
return c;
}
public static Object[] getTwoArray() {
String[] a = { "0", "1", "2" };
String[] b = { "0", "1", "2" };
List aL = Arrays.asList(a);
List bL = Arrays.asList(b);
List resultList = new ArrayList();
resultList.addAll(aL);
resultList.addAll(bL);
Object[] result = resultList.toArray();
return result;
}
public static String[] getThreeArray() {
String[] a = { "0", "1", "2", "3" };
String[] b = { "4", "5", "6", "7", "8" };
String[] c = new String[a.length + b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);
return c;
}
1.两个字符数组合并的问题
public String[] getMergeArray(String[] al,String[] bl) {
String[] a = al;
String[] b = bl;
String[] c = new String[a.length + b.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(b, 0, c, a.length, b.length);
return c;
}
2.字符数组和整形数组合并问题
public int[] getIntArray(int[] al,String[] bl) {
int[] a = al;
String[] b = bl;
int[] ia=new int[b.length];
for(int i=0;i<b.length;i++){
ia[i]=Integer.parseInt(b[i]);
}
int[] c = new int[a.length + ia.length];
System.arraycopy(a, 0, c, 0, a.length);
System.arraycopy(ia, 0, c, a.length, ia.length);
return c;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-07-16
展开全部
int[] s ={4, 7, 2, 3, 1 ,10, 6, 5 ,9 ,8};
int[] s2 = {4,6,2,10,24,9,30,7};
int a[]=new int[s.length+s2.length]; //定义一个长度为s加s2长度的数组
System.arraycopy(s,0,a,0,s.length); //将数组s的元素复制到a中
System.arraycopy(s2,0,a,s.length,s2.length); //将数组s2的元素复制到a中
for(int i=0;i<a.length;i++) //输出新的数组元素a
System.out.println(a[i]);
int[] s2 = {4,6,2,10,24,9,30,7};
int a[]=new int[s.length+s2.length]; //定义一个长度为s加s2长度的数组
System.arraycopy(s,0,a,0,s.length); //将数组s的元素复制到a中
System.arraycopy(s2,0,a,s.length,s2.length); //将数组s2的元素复制到a中
for(int i=0;i<a.length;i++) //输出新的数组元素a
System.out.println(a[i]);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询