java 字符串数组增加长度

来源:百度知道 编辑:UC知道 时间:2024/06/19 12:02:15
String b;
a[a.length+1]=b;
a是一个字符串数组
我想把新字符串b添加到字符串数组a的最后面,请问怎么实现

public class Test{

public static void main(String[] args){
Test t = new Test();
String[] a = {"a","b","c"};
t.reMake(a,"d");
}

public String[] reMake(String[] a,String b){
String[] temp = new String[a.length + 1];
for(int i = 0;i<a.length;i++){
temp[i] = a[i];
}
temp[temp.length-1]=b;
return temp;
}
}

还是用java.util.ArrayList存储吧