How to convert List to int[] in Java?

You can simply iterate through list and fill the array as shown below −

import java.util.ArrayList;
import java.util.List;
public class Tester {
   public static void main(String[] args) {
      List list = new ArrayList();
      list.add(new Integer(1));
      list.add(new Integer(2));
      list.add(new Integer(3));
      list.add(new Integer(4));
      int[] array = new int[list.size()];
      for(int i=0;i

Output

1
2
3
4
Updated on: 2019-07-30T22:30:21+05:30

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements