Here you can find the source of range(int from, int to)
public static long[] range(int from, int to)
//package com.java2s; /*/*w w w . ja va2s. com*/ * Copyright (c) 2016. Sten Martinez * * 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 2 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, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ public class Main { public static long[] range(int from, int to) { if (to < from) { throw new IllegalArgumentException( String.format("to argument %s is less than from argument %s", to, from)); } long[] array = new long[to - from + 1]; int i = 0; for (int j = from; j <= to; j++) { array[i] = j; i++; } return array; } public static long[] range(long from, long to) { if (to < from) { throw new IllegalArgumentException( String.format("to argument %s is less than from argument %s", to, from)); } long[] array = new long[(int) (to - from + 1)]; int i = 0; for (long j = from; j <= to; j++) { array[i] = j; i++; } return array; } }