File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Head First Android this week in the Android 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: 19690

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