Here you can find the source of copyOfRange(int[] original, int from, int to)
Parameter | Description |
---|---|
original | a parameter |
from | a parameter |
to | a parameter |
public static int[] copyOfRange(int[] original, int from, int to)
//package com.java2s; /******************************************************************************* * Copyright (c) Nov 2, 2012 NetXForge./*from w w w . jav a 2s . co m*/ * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, either version 3 of the License, or (at your option) any later * version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/> * * Contributors: Christophe Bouhier - initial API and implementation and/or * initial documentation *******************************************************************************/ public class Main { /** * Copied from class {@link Arrays#copyOfRange(int[], int, int)} , as this * requires java 1.6, and our app should work with 1.5. * * @param original * @param from * @param to * @return */ public static int[] copyOfRange(int[] original, int from, int to) { int newLength = to - from; if (newLength < 0) throw new IllegalArgumentException(from + " > " + to); int[] copy = new int[newLength]; System.arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength)); return copy; } }