Mám pole, ktoré je inicializované takto:
Element[] array = {new Element(1), new Element(2), new Element(3)};
Chcel by som toto pole previesť na objekt triedy ArrayList.
ArrayList<Element> arraylist = ???;
new ArrayList<T>(Arrays.asList(myArray));
Uistite sa, že myArray
je rovnaký typ ako T
. Ak sa napríklad pokúsite vytvoriť List<Integer>
z poľa int
, dostanete chybu kompilátora.