Created
September 27, 2013 09:23
-
-
Save Tzeentchful/6726124 to your computer and use it in GitHub Desktop.
Small util for sorting teams. From desht.
http://forums.bukkit.org/threads/separating-list-into-4-smaller-lists.151302/#post-1697221
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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