Java List Slice slice(List list, int start, int end)

Here you can find the source of slice(List list, int start, int end)

Description

slice

License

Open Source License

Declaration

public static <T> List<T> slice(List<T> list, int start, int end) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012-2015 Codenvy, S.A.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://w  w  w .j a  v a  2s  .  c o  m
 *   Codenvy, S.A. - initial API and implementation
 *******************************************************************************/

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static <T> List<T> slice(List<T> list, int start, int end) {
        List<T> sliced = new ArrayList<>();
        for (int i = start; i < end && i < list.size(); i++) {
            sliced.add(list.get(i));
        }

        return sliced;
    }
}

Related

  1. slice(List as, int start, int end)
  2. slice(List c, int fromIndex, int toIndex)
  3. slice(List list, int index, int count)
  4. slice(List list, Integer start, Integer stop)
  5. sliceList(final List list, final long offset, final int limit)
  6. sliceListByIndices(final List indices, final List list)
  7. slices(List list, int step)