我有一个初始化的数组,如:
Element[] array = {new Element(1), new Element(2), new Element(3)};
我想将此数组转换为ArrayList类的对象.
ArrayList<Element> arraylist = ???;
如何将数组转换为Java中的列表?
我使用Arrays.asList()但行为(和签名)以某种方式从Java SE 1.4.2(现在存档中的文档)更改为8,我在网上找到的大多数片段使用1.4.2行为.
例如:
int[] spam = new int[] { 1, 2, 3 };
Arrays.asList(spam)
在许多情况下,它应该很容易被发现,但有时它可能会被忽视:
Assert.assertTrue(Arrays.asList(spam).indexOf(4) == -1);