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

熱點內容
照片3d建模源代碼 瀏覽:434
西安iPhone6升級內存 瀏覽:84
小學生的編程的課是學什麼的 瀏覽:114
就業下載什麼app 瀏覽:191
個人配置文件重定向到D盤 瀏覽:22
js屏幕寬度 瀏覽:312
sql查找某列重復資料庫 瀏覽:48
智行火車票用微信支付 瀏覽:262
網路定價過程哪些內容發生變化 瀏覽:200
dubbo服務提供者的配置文件 瀏覽:182
win8系統如何壓縮文件 瀏覽:875
網站怎麼上傳代碼 瀏覽:4
java日誌的好處 瀏覽:103
武漢奇米網路怎麼樣 瀏覽:689
筆記本如何恢復原來數據 瀏覽:76
charles怎麼抓取js 瀏覽:580
網路智豹破解版 瀏覽:424
pdf文件一鍵轉藍 瀏覽:563
2014yy釣魚網站源碼 瀏覽:835
華為p9應用程序在哪裡 瀏覽:106

友情鏈接