Here you can find the source of range(int start, int stop)
public static int[] range(int start, int stop)
//package com.java2s; //License from project: Apache License public class Main { public static int[] range(int start, int stop) { return range(start, stop, 1); }/*from ww w.ja v a 2 s . com*/ public static int[] range(int start, int stop, int step) { if (start < stop) { step = Math.abs(step); } else if (start > stop) { step = -Math.abs(step); } else {// start == end return new int[] { start }; } int size = Math.abs((stop - start) / step) + 1; int[] values = new int[size]; int index = 0; for (int i = start; (step > 0) ? i <= stop : i >= stop; i += step) { values[index] = i; index++; } return values; } }