導航:首頁 > 編程語言 > 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數組合並相關的資料

熱點內容
回收站文件清理不在電腦上有痕跡 瀏覽:886
dx版本更新 瀏覽:738
主機集群教程 瀏覽:939
蘋果6英版好不好 瀏覽:959
nodejs抓取網站音頻 瀏覽:772
app上下載的軟體在哪裡 瀏覽:36
起凡保存的照片在哪個文件夾 瀏覽:354
數學建模如何把模型編程 瀏覽:176
ug找不到指定的許可文件 瀏覽:850
數控編程g01表示什麼 瀏覽:700
java實用類 瀏覽:190
去年做哪個網站能致富 瀏覽:727
多少的cad版本能打開pdf格式文件 瀏覽:540
win10文件比率是什麼 瀏覽:652
msdb資料庫置疑 瀏覽:210
移動花卡免流app為什麼要10元 瀏覽:147
xamppphp配置文件 瀏覽:268
刪除ghost文件 瀏覽:642
蘋果7可置換地方 瀏覽:763
win10騰訊文件夾在哪裡 瀏覽:262

友情鏈接