我正在将 C# 代码转换为 Java 代码。
该 C# 代码中使用了 ArrayList。
对于 C# ArrayList,我应该直接在 Java 代码中使用 ArrayList 吗?
当我直接使用时,我收到此警告:
ArrayList is a raw type. References to generic type ArrayList should be parameterized.
我应该做什么改变?
我的 C# 数组列表:
private System.Collections.ArrayList _lines = new System.Collections.ArrayList();
public System.Collections.ArrayList Lines
{
get { return lines; }
}
谢谢。
最佳答案
Java中的
ArrayList需要参数化。您必须定义数据类型。请参阅下面的行来声明 ArrayList
List<String> arrayList = new ArrayList<String>();
arrayList.add("item1");
...
关于C# ArrayList 的 Java 等效项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26505831/