導航:首頁 > 編程語言 > javastring數組合並

javastring數組合並

發布時間:2024-01-10 07:22:16

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];
}
閱讀全文

與javastring數組合並相關的資料

熱點內容
移動花卡免流app為什麼要10元 瀏覽:147
xamppphp配置文件 瀏覽:268
刪除ghost文件 瀏覽:642
蘋果7可置換地方 瀏覽:763
win10騰訊文件夾在哪裡 瀏覽:262
在網站前面加什麼可以看會員視頻 瀏覽:908
哪個讀書app支持格式最全 瀏覽:322
魅族mx3提示網路可能會受到監控 瀏覽:308
如何判斷復制文件是否完整 瀏覽:803
qq接收的語音文件在 瀏覽:408
手機qq禁止查看動態 瀏覽:923
如何用編程求解二重積分 瀏覽:366
在桌面上搜索不到文件夾 瀏覽:723
中外文專利網站有哪些 瀏覽:682
尖刀車端面槽怎麼編程 瀏覽:70
電腦重裝會把所有文件都刪掉嗎 瀏覽:982
java匿名內部類構造函數 瀏覽:573
如何ftp文件到linux 瀏覽:894
win10文件夾的圖片自動排列 瀏覽:155
安卓電腦文件管理器 瀏覽:512

友情鏈接