c# - Java 中的 ArrayLists 和索引器

标签 c# java arrays arraylist

在 Java 中可以做到这一点吗?也许我使用了错误的语法?

ArrayList<Integer> iAL = new ArrayList<Integer>();
iAL.addAll(Arrays.asList(new Integer[] {1, 2, 3, 4, 5 }));

for (int i = 0; i < iAL.size(); ++i) {
    System.out.println(iAL[i]); //<-------- HERE IS THE PROBLEM
}

另外,是否可以做类似的事情

iAL.addAll( new int[] {1, 2, 3, 4, 5} );

如在 C# 上看到的那样?

谢谢

最佳答案

尝试 System.out.println(iAL.get(i));。因为它是一个List,而不是array

关于c# - Java 中的 ArrayLists 和索引器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2351568/

相关文章:

php - 数组键=变量名

android - 在 android spinner 中填充 json 数组

javascript - 按属性对三个不同的对象数组进行排序

c# - 如何计算asp.net gridview itemtemplate文本框中的javascript中两个日期之间的天数

c# - 在 Windows 窗体中访问另一个窗体上的控件的最佳方法?

c# - 等效于 WPF .NET 5、.NET 6 或 .Net Core 中的 UserSettings/ApplicationSettings

c# - 从 C# 到 VB 中的 where 继承

java - 如何使用Gson序列化LocalDate?

java - 为什么java.util.ArrayList中有私有(private)方法outOfBoundsMsg?

java - 使用Dao和Bean类通过MVC模型将数据插入数据库