将数组转换为ArrayList

内容来自 DOC https://q.houxu6.top/?s=将数组转换为ArrayList

给定一个类型为Element[]的数组:

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

如何将这个数组转换为类型为ArrayList<Element>的对象?

ArrayList<Element> arrayList = ???;


将数组转换为ArrayList:

new ArrayList<>(Arrays.asList(array));

posted @ 2023-10-18 20:40  小满独家  阅读(22)  评论(0)    收藏  举报