Create ArrayList from array

后端 未结 30 1869
遇见更好的自我
遇见更好的自我 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条回答
  •  梦毁少年i
    2020-11-21 22:49

    You can convert using different methods

    1. List list = Arrays.asList(array);

    2. List list = new ArrayList();
      Collections.addAll(list, array);

    3. Arraylist list = new Arraylist();
      list.addAll(Arrays.asList(array));

    For more detail you can refer to http://javarevisited.blogspot.in/2011/06/converting-array-to-arraylist-in-java.html

提交回复
热议问题