Java Utililty Methods Array Slice

List of utility methods to do Array Slice

Description

The list of methods to do Array Slice are organized into topic(s).

Method

String[]slice(String[] strings, int begin, int length)
slice
String[] result = new String[length];
System.arraycopy(strings, begin, result, 0, length);
return result;
Listslice(T[] array, int index)
slice
List<T[]> arrayList = new ArrayList<T[]>();
T[] slice1 = Arrays.copyOfRange(array, 0, index);
T[] slice2 = Arrays.copyOfRange(array, index, array.length);
arrayList.add(slice1);
arrayList.add(slice2);
return arrayList;
T[]slice(T[] array, int index, int length)
Returns a new array which is a subset of elements from the given array.
if (array == null || array.length == 0)
    return array;
if (length < 0)
    length = array.length + length;
if (index < 0)
    index += array.length;
if ((length += index) > array.length)
    length = array.length;
...
T[]slice(T[] array, int start, int finish)
Slices an array, where the array [0, 1, 2] sliced from 0 to 2 would return the whole array.
int size = Math.abs(start - finish) + 1;
Object[] newArray = new Object[size];
if (start <= finish) {
    int counter = 0;
    for (int i = start; i <= finish; i++) {
        newArray[counter++] = array[i];
} else {
...
T[]slice(T[] items, int offset, int length)
slice
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));
...
IterablesliceArray(final String[] array, final int start)
slice Array
return new Iterable<String>() {
    String[] values = array;
    int posn = start;
    @Override
    public Iterator<String> iterator() {
        return new Iterator<String>() {
            @Override
            public boolean hasNext() {
...
byte[]SliceByteArray(byte data[], int offset, int length)
Slice Byte Array
byte temp[] = new byte[length];
System.arraycopy(data, offset, temp, 0, length);
return (temp);
byte[]sliceBytes(byte[] bytes, int offset, int length)
slice Bytes
if (null == bytes || bytes.length <= 0) {
    return null;
if (bytes.length < length) {
    throw new Exception("Array index out of bound : " + length);
if ((offset + length) > bytes.length) {
    throw new Exception("Array index out of bound : " + (offset + length));
...
Object[]sliceFromFinalBoundary(Object[] sequence, Boolean[] boundaries)
Return the slice between the final boundary and the end of the sequence.
int last = -1;
for (int i = 0; i < boundaries.length; i++) {
    if (boundaries[i])
        last = i;
return Arrays.copyOfRange(sequence, last + 1, sequence.length, sequence.getClass());
Object[][]slicesFromAllBoundaries(Object[] sequence, Boolean[] boundaries)
Return slices from all boundaries.
List<Object[]> slices = new LinkedList<Object[]>();
int start = -1;
int end = -1;
for (int i = 0; i < boundaries.length; i++) {
    if (boundaries[i]) {
        start = end;
        end = i;
        slices.add(Arrays.copyOfRange(sequence, start + 1, end + 1, sequence.getClass()));
...