Java List Split split(List lst)

Here you can find the source of split(List lst)

Description

Split list in two.

License

Mozilla Public License

Parameter

Parameter Description
lst original list. (Unmodifiable from returned list)
T type

Return

list of two lists

Declaration

public static <T> List<List<T>> split(List<T> lst) 

Method Source Code


//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;
    }
}

Related

  1. split(List list, int size)
  2. split(List list, int size)
  3. split(List list, int size)
  4. split(List list, int size)
  5. split(List list, int splitSize)
  6. split(List toSplit, int howOften)
  7. split(List list, int divide)
  8. splitList(List files, int limit)
  9. splitList(List list, int number)