想要追加数据,需要的流程是:数组-> List-> 数组
案例
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class AddValues {
public static void main(String[] args) {
String[] strings = new String[]{"a", "b", "c", "d"};
//开始添加数据
List<String> arrayList = new ArrayList<String>(Arrays.asList(strings));
// List<String> arrayList = Arrays.asList(strings); //不要这样
arrayList.add("e");
arrayList.add("f");
System.out.println(arrayList);
// 重新赋值
String[] string2 = arrayList.toArray(new String[0]);
System.out.println(Arrays.toString(string2));
}
}