Science, asked by Amaan9276, 1 year ago

How to convert ArrayList to Array and Array to ArrayList in java?

Answers

Answered by rjgolu
3
Let's see a simple example to convert ArrayList to Array and Array to ArrayList in Java:

public class LengthVsSizeArrayList {public static void main(String[] args) {//creating Arraylist.List<String> fruitList = new ArrayList<>();//adding String Objects to fruitsList ArrayList.fruitList.add("Mango");

Answered by Oreki
10

Arrays to ArrayList

String[ ] array = {"Rahul", "Utkarsh", "Shubham", "Neelam"};

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

ArrayList to Arrays

List<String> arrayList = new ArrayList<String> ( );

arrayList.add("Navneet");

arrayList.add("Om");

....

String[ ] array = arrayList.toArray( );

Similar questions