Meaningless Drivel is fun!*
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 Android Security Essentials Live Lessons 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
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: 18541
    
    8

Start with the subList() method.
 
wood burning stoves
 
subject: Dividing a List into chunks
 
Similar Threads
java.lang.outofmemory
How to split a list into 3 lists
Any easy way to split an Arraylist into multiple lists based on a property of the objects?
Where to split methods (Say 4b)
problem of header with Castor 0.9.5