KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
public Collection<Comment> getCommentCollection() { commentCollection = movie.getCommentCollection(); return split((List<Comment>) commentCollection, 4); } public Collection<Comment> split(List<Comment> list, int size){ int numBatches = (list.size() / size) + 1; Collection[] batches = new Collection[numBatches]; Collection<Comment> set = commentCollection; for(int index = 0; index < numBatches; index++) { int count = index + 1; int fromIndex = Math.max(((count - 1) * size), 0); int toIndex = Math.min((count * size), list.size()); batches[index] = list.subList(fromIndex, toIndex); set = batches[index]; } return set; } I am trying to split a bigger collection into smaller collections, depending on the number of items in the original collection. And then return one of the smaller collections every time the get method is called while keeping track of which smaller collection is returned. How can I achieve this?
Tags (comma-separated)
Save Edits
Cancel