What I want to do is very simple using good old loops.
Say I have an object A that contains a List of Bs.
public class A
{
public List<B> myListOfB;
}
In some other method, I have a List of As. Basically, what I want to do is merge all the elements in the lists of Bs of all my As.
For instance, it's very easy to write something like this using loops :
public List<B> someMethod(List<A> myListOfAs)
{
List<B> toReturn = new ArrayList<A>();
for(A myA : myListOfAs)
{
toReturn.addAll(myA.myListOfB);
}
return toReturn;
}
But I would like to do it in a more fonctionnal way using Guava. This example is very easy, but it could be much more complex with conditions for instance, hence it makes sense to use functional programming.
I'm very new to Guava. I've started using it for filtering and ordering, but I'm pretty sure it might also be possible to use it, but I haven't been able to figure out how. I found this Combine multiple Collections into a single logical Collection? but it doesn't really answer my question.