Benefits of creating a List using Arrays.asList()

This question already has an answer here:

  • Why does Arrays.asList() return its own ArrayList implementation 6 answers

  • Not being able to call add, remove, etc is the exact difference. If you don't need those methods, Arrays.asList gives you a perfectly fine view of the array as a List (for APIs that take collections rather than arrays). If you need to change the "shape" of the list, then new ArrayList<>(Arrays.asList(myArray)) is the way to go.

    链接地址: http://www.djcxy.com/p/2910.html

    上一篇: 在JavaScript中删除数组元素

    下一篇: 使用Arrays.asList()创建列表的好处