The following method should do the trick:
public static <T> void merge(ArrayList<ArrayList<T>> arrayLists) {
int blockSize = 6;
for(int i=blockSize; i<arrayLists.size(); i++) {
arrayLists.get(i % blockSize).addAll(arrayLists.get(i));
}
arrayLists.subList(blockSize, arrayLists.size()).clear();
}
You can convert blockSize
to the method parameter if you like.
1
solved Merge Arraylists inside an ArrayLists of Arraylists [closed]