aspose file tools*
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
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

Start with the subList() method.
 
wood burning stoves
 
subject: Dividing a List into chunks