Class ListUtils


  • public class ListUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      ListUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <T> java.util.List<java.util.List<T>> partition​(java.util.List<T> list, int size)
      Returns consecutive sublists of a list, each of the same size (the final list may be smaller).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ListUtils

        public ListUtils()
    • Method Detail

      • partition

        public static <T> java.util.List<java.util.List<T>> partition​(java.util.List<T> list,
                                                                      int size)
        Returns consecutive sublists of a list, each of the same size (the final list may be smaller). For example, partitioning a list containing [a, b, c, d, e] with a partition size of 3 yields [[a, b, c], [d, e]] -- an outer list containing two inner lists of three and two elements, all in the original order.

        The outer list is unmodifiable, but reflects the latest state of the source list. The inner lists are sublist views of the original list, produced on demand using List.subList(int, int), and are subject to all the usual caveats about modification as explained in that API.

        Adapted from http://code.google.com/p/guava-libraries/

        Type Parameters:
        T - the element type
        Parameters:
        list - the list to return consecutive sublists of
        size - the desired size of each sublist (the last may be smaller)
        Returns:
        a list of consecutive sublists
        Throws:
        java.lang.NullPointerException - if list is null
        java.lang.IllegalArgumentException - if size is not strictly positive
        Since:
        4.0