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

后端 未结 6 485
小蘑菇
小蘑菇 2020-12-02 12:55

I recently found out that there are actually 2 different ArrayList implementations in Java (better late than never I guess...).

So I was wondering why d

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 13:55

    Arrays.asList needs to return a list that cannot be resized -- because the underlying array cannot be resized -- but that is modifiable -- because assignment to elements in the underlying array is allowed.

提交回复
热议问题