Java List Shift shiftElementsToEnd(final List source, final int count)

Here you can find the source of shiftElementsToEnd(final List source, final int count)

Description

returns a list of everything in source, with the first count units moved to the end

License

Open Source License

Declaration

public static <T> List<T> shiftElementsToEnd(final List<T> source, final int count) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**//w ww  .  ja v  a2s  .c  o m
     * returns a list of everything in source, with the first count units moved to the end
     */
    public static <T> List<T> shiftElementsToEnd(final List<T> source, final int count) {
        final ArrayList<T> rVal = new ArrayList<>(source.size());
        for (int i = count; i < source.size(); i++) {
            rVal.add(source.get(i));
        }
        for (int i = 0; i < count; i++) {
            rVal.add(source.get(i));
        }
        if (source.size() != rVal.size()) {
            throw new IllegalStateException("Didnt work for: " + count + " " + source + " : " + rVal);
        }
        return rVal;
    }
}

Related

  1. shift(List list)
  2. shift(String s, int length, List list, StringBuffer res)