Drops enough strings from the first array to fill the second one beginning with the last object. - Java Collection Framework

Java examples for Collection Framework:Array Element

Description

Drops enough strings from the first array to fill the second one beginning with the last object.

Demo Code


//package com.java2s;

public class Main {
    /**/*www .  ja  v a2  s  .  com*/
     * Drops enough strings from the first array to fill the second one
     * beginning with the last object.
     * 
     * @param from the array to take the object from
     * @param to the array to write the objects to
     * @throws IllegalArgumentException If the second array is not shorter than the first one.
     * 
     * @author TheMrMilchmann
     * @since DerpieLang v1.0.0
     */
    public static final <T> T[] dropFromEnd(T[] from, T[] to) {
        if (from.length <= to.length)
            throw new IllegalArgumentException(
                    "First array must be longer than the second one!");

        for (int i = 0; i < to.length; i++) {
            to[i] = from[i];
        }

        return to;
    }
}

Related Tutorials