Free tutorials for Java, Eclipse and Web programming



Follow me on twitter

Split / Partition a collection into smaller collections - Java

Lars Vogel

Version 0.1

17.01.2010

Revision History
Revision 0.117.01.2010Lars Vogel
Created

Partition a collection into smaller collections

This article describes how to partition a collections into a given number of smaller collections.


Table of Contents

1. Partition a collection
2. Partition collection in Java
2.1. Implementation
2.2. Test
3. Thank you
4. Questions and Discussion
5. Links and Literature
5.1. Source Code
5.2. General

1. Partition a collection

Sometime you want split a collection into smaller collections. The following gives an example how to do this.

Tip

Please note that this example is an adjusted example of the Google collection and more or less the same as Code Ranch discussion The Google source code can be found here Original source code

The test code also demonstrate how to calculate the number of elements which should go into one bucket in case you want to have a fixed number of buckets.