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.

Array in java is index based, first element of the array is stored at 0 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))

AN OTHER EXAMPLES

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

No comments:

Post a Comment