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

前端 未结 4 1309

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 11:08

    Collection collection1 = ...
    Collection collection2 = ...
    Collection collection3 = ...
    ...
    
    Collection all = ...
    all.addAll(collection1);
    all.addAll(collection2);
    all.addAll(collection3);
    ...
    
    for(Foo element : all)
    {
    
    }
    

提交回复
热议问题