java三种字符数组合并的方法
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
三种字符数组合并的方法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 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; }