How to copy all elements of ArrayList to an Object Array in Java

1 Answer

0 votes
package javaapplication1;

import java.util.ArrayList;

public class JavaApplication1 {

    public static void main(String[] args) {

        ArrayList arrList = new ArrayList();
   
        arrList.add("Java");
        arrList.add("C#");
        arrList.add("C++");
        arrList.add("PHP");
        
        Object[] objArr = arrList.toArray();

        for (Object oa : objArr) 
            System.out.println(oa);
  }
}
  
/*
run:
 
Java
C#
C++
PHP
  
*/

 



answered Sep 21, 2016 by avibootz

Related questions

1 answer 232 views
2 answers 220 views
2 answers 213 views
2 answers 268 views
2 answers 121 views
121 views asked Oct 9, 2023 by avibootz
1 answer 176 views
...