This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma 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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Dividing a List into chunks" Watch "Dividing a List into chunks" New topic

Dividing a List into chunks

Ronwaldo Cruz
Ranch Hand

Joined: Oct 17, 2006
Posts: 69

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

Joined: Oct 14, 2005
Posts: 19973

Start with the subList() method.
I agree. Here's the link:
subject: Dividing a List into chunks
It's not a secret anymore!