- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 an array of objects to an array of their primitive types in java?
Apache Commons provides a library named org.apache.commons.lang3 and, following is the maven dependency to add the library to your project.
<dependencies> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.0</version> </dependency> </dependencies>
This package provides a class named ArrayUtils. Using the toPrimitive() method of this class you can convert An object array to an array of primitive types:
Example
import java.util.Arrays; import org.apache.commons.lang3.ArrayUtils; public class ArraysToPrimitives { public static void main(String args[]) { Integer[] myArray = {234, 76, 890, 27, 10, 63}; int[] primitiveArray = ArrayUtils.toPrimitive(myArray); System.out.println(Arrays.toString(primitiveArray)); } }
Output
[234, 76, 890, 27, 10, 63]
- Related Articles
- How to convert nested array pairs to objects in an array in JavaScript ?
- How to convert an object array to an integer array in Java?
- C++ Program to convert primitive types to objects
- Golang program to convert primitive types to objects
- Convert array of objects to an object of arrays in JavaScript
- How to convert Wrapper value array list into primitive array in Java?
- How to convert JavaScript objects to primitive data types manually?
- Program to convert Primitive Array to Stream in Java
- How to convert an array to string in java?
- How to sort an array of objects containing null elements in java?
- How to create an array of objects in TypeScript?
- How to convert array of comma separated strings to array of objects?
- Search from an array of objects via array of string to get array of objects in JavaScript
- Convert LinkedList to an array in Java
- Convert an ArrayList to an Array with zero length Array in Java

Advertisements