LoginSignup
3
3

More than 5 years have passed since last update.

Guavaでネストしたループのtransform

Posted at
for(Continent continent : continentList) 
{
    for(Country country : continent.getCountries())
    {
        for(City city : country.getCities())
        {
            //Do stuff with city objects
        }
    }
}

上記のようなネストしたループでLists.transformを使いたい場合は、

FluentIterable.from(continentList)
    .transformAndConcat(Continent.getCountriesFunction())
    .transformAndConcat(Country.getCitiesFunction())
    . //filter //tranform //find //toList() //etc.

のようにtransformAndConcat()を使えば出来なくもないが、メンテしづらくなるためお勧め出来ないとのこと。

java - Guava iterators, and iterating over a list within a list object - Stack Overflow

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3