I have a requirement where i have to print the values which are getting saved in a database. I have pojo object which i am passing it in a list and then saving the entire list in database. Please find the below code.
List dataList=new ArrayList();
Vehicles vehiclePojoObject=new Vehicles();
vehiclePojoObject.setName("Cycle");
vehiclePojoObject.setColor("Blue");
dataList.add(vehiclePojoObject);
Now i have to print the values which is contained by vehiclePojoObject. How can it be acheived. Please guide. Thanks in advance.
Note: There are not one object but multiple objects which are getting stored in the list.
Assuming that you want to store objects of different types on the same list and have a single method for printing all private fields of those object regardless of their types you can use the (reflection API). By the help of reflection we can change behavior of list at runtime