java如果我不知道数组会有多少个元素?
我想举个例子
import java.util.Scanner;
public class ana
{
public static void main(String[] args) {
int[] array = new int[9]; // create array that have "9" elements
}
}
上面示例的数组有9个元素,但我想创建无限数组。 如果我在编写PHP时需要这样做,我会编写以下代码:
<?php
$example = array();
$example[] = 15; // auto numbering. PHP don't want number of array's element.
$example[] = 20;
?>
这意味着什么
Auto[] array = {new Auto()};
我希望我说清楚了
# 1 楼答案
在java中使用ArrayList
# 2 楼答案
您需要使用不同的数据结构,比如
Vector