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