Skip to content

Instantly share code, notes, and snippets.

@Tzeentchful
Created September 27, 2013 09:23
Show Gist options
  • Save Tzeentchful/6726124 to your computer and use it in GitHub Desktop.
Save Tzeentchful/6726124 to your computer and use it in GitHub Desktop.
public static <T> List<T>[] splitList(List<T> list, int nLists) {
@SuppressWarnings("unchecked")
List<T>[] res = (ArrayList<T>[]) new ArrayList[nLists];
Collections.shuffle(list);
for (int i = 0; i < list.size(); i++) {
res[i % nLists].add(list.get(i));
}
return res;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment