tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 
 Tools and Libs > Google Guava > Collections > List Partition

List Partition 

Google Guava is a java library with lot of utilities and reusable components. This requires the library guava-10.0.jar to be in classpath. The following example shows using Lists.partition() API. It splits the given list into sublists of provided partition size.

File Name  :  
com/bethecoder/tutorials/guava/collection_tests/ListSubListTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.guava.collection_tests;

import java.util.List;

import com.google.common.collect.Lists;

public class ListSubListTest {

  /**
   @param args
   */
  public static void main(String[] args) {
    List<Integer> intList = Lists.newArrayList(12345678);
    System.out.println(intList);
    
    System.out.println("\nSubsets : ");
    List<List<Integer>> subSets = Lists.partition(intList, 3);
    for (List<Integer> subSet : subSets) {
      System.out.println(subSet);
    }
  }

}
   

It gives the following output,
[1, 2, 3, 4, 5, 6, 7, 8]

Subsets : 
[1, 2, 3]
[4, 5, 6]
[7, 8]


                    Print

   



Books Recommendation

 
 
bl  br