This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Dividing a List into chunks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Dividing a List into chunks" Watch "Dividing a List into chunks" New topic
Author

Dividing a List into chunks

Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69
Hi,

I'm having trouble dividing a List of Objects into several chunks. I have an ArrayList of unknown(variable) no. of objects and I want to split them into groups of 300. So suppose I receive a List of 1000 objects I need a method that will return a List of Lists (List of 4 Lists containing 300, 300, 300, & 100 objects respectively)

public List<List> split(List bigChunk)
{

}

Does anybody have an idea?
Paul Clapham
Sheriff

Joined: Oct 14, 2005
Posts: 19720
    
  10

Start with the subList() method.
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Dividing a List into chunks
 
jQuery in Action, 3rd edition