A. java 中如何将 "字符串数组" 合并成 "一个字符串" 例如String [] ss = new String [n] 字符串数组中有n个
1.先建立一个StringBuffer对象
2.然后对你想合并的该字符串数组String [] ss遍历,遍历的时候,通过使用StringBuffer的append()方法,版将每个ss[i]中权的值加入到StringBuffer中
3.如果想得到String,就调用StringBuffer的toString()方法!
B. java如何把两个二维数组合并成一个,高效的方法,希望大家给点意见
以String为例的一个示例。
import java.util.*;
public class Test {
public static void main(String[] args) {
String[][] strs1 = {{"start", "htr", "fa"},
{"543", "gfd", "gs"},
{"jh", "k", "gsk"},
{"675", "hfhgf"}};
String[][] strs2 = {{"fdsa", "432", "fds"},
{"j","hgf34"},
{"765", "gfj", "456", "jkl"},
{"lkjhl", "gfds", "hgfh", "end"}};
String[][] strs3 = unite(strs1, strs2);
for(String[] list : strs3) {
for(String s : list) {
System.out.print(s + " ");
}
System.out.println();
}
}
public static String[][] unite(String[][] os1, String[][] os2) {
List<String[]> list = new ArrayList<String[]>(Arrays.<String[]>asList(os1));
list.addAll(Arrays.<String[]>asList(os2));
return list.toArray(os1);
}
}
C. java String数组合并
String tr = "";
for (int i = 0; i < str.length; i++) {
tr = tr + ',' + str[i];
}
tr = tr + ',' + tem[4];
tr = tr + ',' + tem[1];
tr = tr + ',' + tem[0];
D. java两个数组合并用for循环
//两个数组
String[] str1 = {"a","b","c"};
String[] str2 = {"d","e","f"};
//创建一个要接收的数组
String[] str3= new String[str1.length+str2.length];
//先把第一个数组放进去
for(int x=0;x<str1.length;x++){
str3[x] = str1[x];
}
for(int y=0;y<str2.length;y++){
str3[str1.length+y]=str2[y];
}
for(int y=0;y<str3.length;y++){
System.out.println(str3[y] + " ");
}
如有帮助请采纳(不懂请提问),可以看我主页,欢迎来交流学习;
E. Java如何合并两个数组
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.array(a, 0, c, 0, a.length);
System.array(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.array(a, 0, c, 0, a.length);
System.array(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.array(a, 0, c, 0, a.length);
System.array(ia, 0, c, a.length, ia.length);
return c;
}
F. java怎么将2个数组的数据合并
不记得有可以合并两个数组的方法,感觉基本只能手动了,如:
intindex=0;
intc[]=newint[a.length+b.length];
for(inti=0;i<a.length;i++){
c[index++]=a[i];
}
for(inti=0;i<b.length;i++){
c[index++]=b[i];
}