Iterate through multiple collections in the same “for” loop?

前端 未结 4 1310

I wonder if there\'s such a way to iterate thru multiple collections with the extended for each loop in java.

So something like:

for (Object element          


        
4条回答
  •  误落风尘
    2020-12-17 10:55

    You can do exactly this with Guava's Iterables.concat():

    for (Foo element : Iterables.concat(collection1, collection2)) {
        foo.frob();
    }
    

提交回复
热议问题