slice Summary Returns a subset of the array beginning at the specified index until the end of the array. Signatures Click on a signature to select it and view its documentation. public T[] slice(int begin) public T[] slice(int begin, int end) Usage public T[] slice(int begin) public T[] slice(int begin, int end) Returns A shallow copy representing the subset of the array beginning at the specified index until the end of the array. A shallow copy representing the subset of the array beginning at the specified starting index until the specified ending index. Parameters begin Zero-based index to begin extraction from. This argument can be negative to begin the slice from the end of the array. Parameters begin Zero-based index to begin extraction from. This argument can be negative to begin the slice from the end of the array. end One-based index to end extraction at. This argument can be negative to end the slice at an element relative to the end of the array. Description Returns a shallow copy representing the subset of the array beginning at the specified index until the end of the array. This method does not mutate the array. Returns a shallow copy representing the subset of the array beginning at the specified starting index (zero-based) to the specified ending index (one-based). This method does not mutate the array. Examples Slicing from the beginning of the array 123import System; [ 1, 2, 3, 4, 5 ].slice(1); // [ 2, 3, 4, 5 ] Slicing from the end of the array 123import System; [ 1, 2, 3, 4, 5 ].slice(-2); // [ 4, 5 ] Basic Usage 123import System; [ 1, 2, 3, 4, 5 ].slice(0, 2); // [ 1, 2 ] Extract the first to penultimate element 123import System; [ 1, 2, 3, 4, 5 ].slice(0, -1); // [ 1, 2, 3, 4 ] Share HTML | BBCode | Direct Link