Create ArrayList from array

后端 未结 30 1795
遇见更好的自我
遇见更好的自我 2020-11-21 22:29

I have an array that is initialized like:

Element[] array = {new Element(1), new Element(2), new Element(3)};

I would like to convert this

30条回答
  •  隐瞒了意图╮
    2020-11-21 22:49

    According with the question the answer using java 1.7 is:

    ArrayList arraylist = new ArrayList(Arrays.asList(array));
    

    However it's better always use the interface:

    List arraylist = Arrays.asList(array);
    

提交回复
热议问题