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

熱點內容
網路中常用的傳輸介質 瀏覽:518
文件如何使用 瀏覽:322
同步推密碼找回 瀏覽:865
樂高怎麼才能用電腦編程序 瀏覽:65
本機qq文件為什麼找不到 瀏覽:264
安卓qq空間免升級 瀏覽:490
linux如何刪除模塊驅動程序 瀏覽:193
at89c51c程序 瀏覽:329
怎麼創建word大綱文件 瀏覽:622
裊裊朗誦文件生成器 瀏覽:626
1054件文件是多少gb 瀏覽:371
高州禁養區內能養豬多少頭的文件 瀏覽:927
win8ico文件 瀏覽:949
仁和數控怎麼編程 瀏覽:381
項目文件夾圖片 瀏覽:87
怎麼在東芝電視安裝app 瀏覽:954
plc顯示數字怎麼編程 瀏覽:439
如何辨別假網站 瀏覽:711
寬頻用別人的賬號密碼 瀏覽:556
新app如何佔有市場 瀏覽:42

友情鏈接