How to convert ArrayList to Array and Array to ArrayList in java?
Answers
Answered by
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");
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
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