Here you can find the source of split(List
Parameter | Description |
---|---|
lst | original list. (Unmodifiable from returned list) |
T | type |
public static <T> List<List<T>> split(List<T> lst)
//package com.java2s; /*/*from w ww. j av a 2 s .com*/ * Copyright (c) 2014 Tor C Bekkvik * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.util.*; public class Main { /** * Split list in two. * * @param lst original list. (Unmodifiable from returned list) * @param <T> type * @return list of two lists */ public static <T> List<List<T>> split(List<T> lst) { List<List<T>> tmp = new ArrayList<>(); int N = lst.size(); tmp.add(new ArrayList<>(lst.subList(0, N / 2))); tmp.add(new ArrayList<>(lst.subList(N / 2, N))); return tmp; } }