How to convert ArrayList to Array in Java

Arraylist has a method toArray() to convert List to Array.

Example

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class JavaApplication1 {

  
    public static void main(String[] args) {
        
        List<String> list = new ArrayList<String>();

        list.add("android");
        list.add("apple");
        String[] stringArray = list.toArray(new String[0]);
        
      
        for(int k=0;k<stringArray.length;k++)
        System.out.println(stringArray[k]);
    }
    
}

 

Output

android
apple

 


Subscribe For Daily Updates

Flutter Questions
Android Questions