Lists.partition用法

将list集合按指定长度进行切分,返回新的List>集合,如下的:

  List> lists=Lists.partition(numList,3);

package test;

import com.google.common.collect.Lists;
import org.junit.Test;

import java.util.List;

/**
 * Created by Administrator on 2018/10/28/028.
 */
public class testList {

    @Test
    public void  test(){
        List numList = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8);

        List> lists=Lists.partition(numList,3);
        System.out.println(lists);//[[1, 2, 3], [4, 5, 6], [7, 8]]

    }

}

 

你可能感兴趣的:(JAVA)