org.limewire.collection
Class ListPartitioner<E>
java.lang.Object
org.limewire.collection.ListPartitioner<E>
public class ListPartitioner<E>
- extends Object
Partitions a list into sublists with equal size. The remainder items in the
list are included with the last sublist. For example, list = {1,2,3,4,5} and 2
partitions makes subList1 = {1,2} and subList2 = {3,4,5}.
LinkedList<String> list = new LinkedList<String>();
for(int i = 1; i < 6; i++)
list.add(String.valueOf(i));
System.out.println(list);
ListPartitioner<String> lp = new ListPartitioner<String>(list, 2);
List<String> p1 = lp.getPartition(0);
List<String> p2 = lp.getPartition(1);
System.out.println("partition 1: " + p1);
System.out.println("partition 2: " + p2);
Output:
[1, 2, 3, 4, 5]
partition 1: [1, 2]
partition 2: [3, 4, 5]
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ListPartitioner
public ListPartitioner(List<E> list,
int numPartitions)
getPartition
public List<E> getPartition(int index)
getLastPartition
public List<E> getLastPartition()
getFirstPartition
public List<E> getFirstPartition()
Copyright © 2008 Lime Wire LLC. All Rights Reserved.