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

后端 未结 6 490
小蘑菇
小蘑菇 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:36

    actually you are able to add elements to the ArrayList with add. method like this :

    List l2= new ArrayList(Arrays.asList(array1));
    l2.add("blueCheese");
    

    In my opinion you use it to get the features of a List but applying them to an Array .

提交回复
热议问题