我有一个基本字符串数组
String[] array = {
"AAA",
"BBB",
"CCC"
};
现在我想向其中添加一个新项目
array[array.length + 1] = "DDD"
运行应用程序后它崩溃了。
最佳答案
An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.
如果您想动态更改大小,那么您应该使用 ArrayList
或者您也可以使用HashMap
关于java - 将新项目添加到字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25447303/