Java Array Slice slice(T[] items, int offset, int length)

Here you can find the source of slice(T[] items, int offset, int length)

Description

slice

License

Apache License

Parameter

Parameter Description
T a parameter
items a parameter
offset - 0 based
length - 1 based

Exception

Parameter Description
UtilityException an exception

Declaration

public static <T> T[] slice(T[] items, int offset, int length) throws Exception 

Method Source Code

//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)));
    }
}

Related

  1. slice(String[] strings, int begin, int length)
  2. slice(String[] strings, int begin, int length)
  3. slice(T[] array, int index)
  4. slice(T[] array, int index, int length)
  5. slice(T[] array, int start, int finish)
  6. sliceArray(final String[] array, final int start)
  7. SliceByteArray(byte data[], int offset, int length)
  8. sliceBytes(byte[] bytes, int offset, int length)
  9. sliceFromFinalBoundary(Object[] sequence, Boolean[] boundaries)