
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
Convert Integer ArrayList to Integer Array in Java
To convert integer array list to integer array is not a tedious task. First, create an integer array list and add some elements to it −
ArrayList < Integer > arrList = new ArrayList < Integer > (); arrList.add(100); arrList.add(200); arrList.add(300); arrList.add(400); arrList.add(500);
Now, assign each value of the integer array list to integer array. We used size() to get the size of the integer array list and placed the same size to the newly created integer array −
final int[] arr = new int[arrList.size()]; int index = 0; for (final Integer value: arrList) { arr[index++] = value; }
Example
import java.util.ArrayList; public class Demo { public static void main(String[] args) { ArrayList<Integer>arrList = new ArrayList<Integer>(); arrList.add(100); arrList.add(200); arrList.add(300); arrList.add(400); arrList.add(500); arrList.add(600); arrList.add(700); arrList.add(800); arrList.add(900); arrList.add(1000); final int[] arr = new int[arrList.size()]; int index = 0; for (final Integer value : arrList) { arr[index++] = value; } System.out.println("Elements of int array..."); for (Integer i : arr) { System.out.println(i); } } }
Output
Elements of int array... 100 200 300 400 500 600 700 800 900 1000
Advertisements