Create arraylist from array

Create Arraylist from array,In some of the interviews may or may not ask this question but it is tricky question in Java,here i’ve given simple code to creating arraylist from array,below is the simple code.

Java array is an object the contains elements of similar data type. It is a data structure where we store similar elements. We can store only fixed set of elements in a java array.
Verify list is empty

Array in java is index based, first element of the array is stored at index.

a[] array={33,3,4,5};

Code to convert into ArrayList:

ArraryList<> arrayList = new ArrayList<>(Arrays.asList(array))

ArrayList<> arrayList=new ArrayList<>(Arrays.asList(array))


List<Element> arraylist = Arrays.asList(new Element(1), new Element(2), new Element(3));

ALSO READ  When to use LinkedList over ArrayList

Rajesh K

Leave a Reply

Your email address will not be published. Required fields are marked *