Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert List<Integer> 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<Integer> 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<array.length;i++) {
array[i] = list.get(i);
System.out.println(array[i]);
}
}
}
Output
1 2 3 4
Advertisements