Arrays.asList() doubt?

前端 未结 8 1244
粉色の甜心
粉色の甜心 2020-12-05 08:00

People say that asList method convert the array into list and its not copying, so every change in \'aList\' will reflect into \'a\'. So add new values in \'aLis

相关标签:
8条回答
  • 2020-12-05 08:54

    asList returns a fixed-size list, so that you cannot add new elements to it. Because the list it returns is really a "view" of the array it was created from ('a' in your case), it makes sense that you won't be able to add elements - just like you can't add elements to an array. See the docs for asList

    0 讨论(0)
  • 2020-12-05 08:55

    This List implementation you receive from Arrays.asList is a special view on the array - you can't change it's size.

    The return type of Arrays.asList() is java.util.Arrays.ArrayList which is often confused with java.util.ArrayList. Arrays.ArrayList simply shows the array as a list.

    0 讨论(0)
提交回复
热议问题