Given the list of Foo myFoos, I need to map them to a collection of another class, like Bar. Now I do it like this:
List<Bar> myBars = new...
for(Foo f : foos) {
Bar b = new Bar();
b.setAProperty(f.getProperty);
b.setAnotherProp(f.getAnotherProp);
myBars.add(b);
}
So, is there an easier way to do this? Of course, this is pretty easy, but I wonder if there is any magic out there that would turn foos into bars without having to manually browse through the list, especially because my input list could be large.
If not, did you know, did you know the compiler to optimize this? My main concern is performance.
Thank!
- Llappall Page
source
share