I know that BeanUtils can copy a single object to other.
Is it possible to copy an arraylist.
For example:
FromBean fromBean = new FromBean("fromBean", "fromBeanAProp", "fromBeanBProp");
ToBean toBean = new ToBean("toBean", "toBeanBProp", "toBeanCProp");
BeanUtils.copyProperties(toBean, fromBean);
How to achieve this?
List<FromBean > fromBeanList = new ArrayList<FromBean >();
List<ToBean > toBeanList = new ArrayList<ToBean >();
BeanUtils.copyProperties(toBeanList , fromBeanList );
Its not working for me. Can any one please help me.
Thanks in advance.
If you have a list origin with data and list destination empty, the solution is:
List<Object> listOrigin (with data)
List<Object> listDestination= new ArrayList<Object>();
for (Object source: listOrigin ) {
Object target= new Object();
BeanUtils.copyProperties(source , target);
listDestination.add(target);
}