Replace various for loops which add items to collections with calls to Collections.addAll(...). Fixes gh-2277