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
Given Object Array:
Element[] array = {new Element(1), new Element(2), new Element(3) , new Element(2)};
Convert Array to List:
List list = Arrays.stream(array).collect(Collectors.toList());
Convert Array to ArrayList
ArrayList arrayList = Arrays.stream(array)
.collect(Collectors.toCollection(ArrayList::new));
Convert Array to LinkedList
LinkedList linkedList = Arrays.stream(array)
.collect(Collectors.toCollection(LinkedList::new));
Print List:
list.forEach(element -> {
System.out.println(element.i);
});
OUTPUT
1
2
3