List of utility methods to do Array Slice
int[] | arraySlice(int[] source, int start, int count) Returns a range of elements of source from start to end of the array. int[] slice = new int[count]; System.arraycopy(source, start, slice, 0, count); return slice; |
Object[] | arraySlice(Object[] source, Object[] dest, int startIdx) array Slice for (int i = startIdx; i < dest.length; i++) { dest[i] = source[i]; return dest; |
byte[] | slice(byte[] buffer, int start, int end) slice return Arrays.copyOfRange(buffer, start, end);
|
byte[] | slice(byte[] source, int start, int end) slice if (start < 0 || end > source.length) { throw new IllegalArgumentException("start or end is out of bound"); byte[] target = new byte[end - start]; System.arraycopy(source, start, target, 0, target.length); return target; |
Object[] | slice(Object[] objects, int begin, int length) slice Object[] result = new Object[length]; for (int i = 0; i < length; i++) { result[i] = objects[begin + i]; return result; |
String[] | slice(String source[], int start, int end) slice if (source == null) return null; if (start == end) return new String[0]; int e = Math.max(start, end); e = Math.min(e, source.length); int s = Math.min(start, end); String newArray[] = new String[e - s]; ... |
String[] | slice(String[] array, int a, int b) slice String[] newarray = new String[b - a]; if (!(a < array.length && b <= array.length)) { throw new Exception("out of bound:" + a + "," + b); for (int i = a; i < b; i++) { newarray[i - a] = array[i]; return newarray; ... |
String[] | slice(String[] array, int index, int length) slice String[] slice = new String[length]; for (int i = 0; i < length; i++) { slice[i] = array[index + i]; return slice; |
String[] | slice(String[] o, int index) Slices an array at the given index. String[] result = new String[o.length - index]; for (int i = index; i < o.length; i++) { result[i - index] = o[i]; return result; |
String[] | slice(String[] strings, int begin, int length) slice String[] result = new String[length]; System.arraycopy(strings, begin, result, 0, length); return result; |