Convert class to array object in java

Wednesday, April 5th, 2017 (0 Comment)

In this article, we will focus on convert class to array object in java. After that, we convert list class to list array object.

Example: cast Customer Class to Object[] and cast List<Customer> to List<Object[]>.

You need import java.lang.reflect.Field

1) Declare Customer Class

Example 1: Customer Class to Object[]

2) Convert class to array object in java

2.1. Function get list fields name or properties name of Class and convert them to array

Main

Output:

2.2. Function get list values of Class and convert them to array object

Main

Output:

Example 2: List<Customer> to List<Object[]>.

3) Convert list class to list array object in java

Function get list fields name of class and get list values of class, after that convert to object array

Main

Output:

 

Tags: , , , ,

Related Posts

core java
Export Crystal Report with Subreport in java
core java
Convert xml to object java and vice versa
core java
Java basic tutorial on lvtutorial.com
core java
Java hibernate manytomany to manage user role

Related Posts

core java
Export Crystal Report with Subreport in java
core java
Convert xml to object java and vice versa
core java
Java basic tutorial on lvtutorial.com
core java
Java hibernate manytomany to manage user role

Leave a Reply

Your email address will not be published. Required fields are marked *