Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.util.Arrays;

public class Main {
    /**
     * 
     * @param <T>
     * @param items
     * @param offset
     *            - 0 based
     * @param length
     *            - 1 based
     * @return
     * @throws UtilityException
     */
    public static <T> T[] slice(T[] items, int offset, int length) throws Exception {
        if (null == items || items.length <= 0) {
            return null;
        }
        if (items.length < length) {
            throw new Exception("Array index out of bound : " + length);
        }
        if ((offset + length) > items.length) {
            throw new Exception("Array index out of bound : " + (offset + length));
        }

        return Arrays.<T>copyOfRange(items, offset, (offset + (length - 1)));
    }
}