Java Number Range Create range(int start, int stop)

Here you can find the source of range(int start, int stop)

Description

range

License

Apache License

Declaration

public static int[] range(int start, int stop) 

Method Source Code

//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;
    }
}

Related

  1. range(int start, int end)
  2. range(int start, int end)
  3. range(int start, int end, int step)
  4. range(int start, int length)
  5. range(int start, int length, int step)
  6. range(int startValue, int endValue)
  7. range(int unit)
  8. range(int v, int min, int max)
  9. range(int value, int min, int max)