The Java API 文档说 http://java.sun.com/javase/6/docs/api/java/util/Collections.html#addAll(java.util.Collection,%20T...)以下关于Collections.addAll
此便捷方法的行为与 c.addAll(Arrays.asList(elements)) 的行为相同,但此方法在大多数实现下可能运行速度明显更快。
所以如果我理解正确的话,a) 比 b) 慢:
a)
Collection<Integer> col = new ArrayList<Integer>();
col.addAll(Arrays.asList(1, 2, 3, 4, 5));
b)
Collection<Integer> col = new ArrayList<Integer>();
// Collections.addAll(col, Arrays.asList(1, 2, 3, 4, 5)); <-- won't compile
Collections.addAll(col, 1, 2, 3, 4, 5);
谁能向我解释一下这是为什么?
编辑:
更正的代码示例。谢谢多基因润滑剂 https://stackoverflow.com/users/276101/polygenelubricants