Here you can find the source of slice(T[] items, int offset, int length)
Parameter | Description |
---|---|
T | a parameter |
items | a parameter |
offset | - 0 based |
length | - 1 based |
Parameter | Description |
---|---|
UtilityException | an exception |
public static <T> T[] slice(T[] items, int offset, int length) throws Exception
//package com.java2s; //License from project: Apache License import java.util.Arrays; public class Main { /**/*w ww . jav a 2 s . c o m*/ * * @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))); } }