Java Number Range Create range(int min, int max)

Here you can find the source of range(int min, int max)

Description

Java implementation of Python's range() function, without steps

License

Open Source License

Parameter

Parameter Description
min lower bound
max upper bound

Return

an array of integers between min (inclusive) and max (exclusive). Returns an empty array if min > max

Declaration

public static int[] range(int min, int max) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*from   w w w . jav  a2 s  . c om*/
     * Java implementation of Python's range() function, without steps
     * 
     * @param min
     *            lower bound
     * @param max
     *            upper bound
     * @return an array of integers between min (inclusive) and max (exclusive).
     *         Returns an empty array if min > max
     */
    public static int[] range(int min, int max) {
        if (min > max) {
            return new int[0];
        }
        int[] rv = new int[max - min];

        for (int i = 0; i < (max - min); i++) {
            rv[i] = min + i;
        }
        return rv;
    }
}

Related

  1. range(int from, int to)
  2. range(int i, int j)
  3. Range(int k, int from, int end)
  4. range(int low, int high)
  5. range(int min, int max)
  6. range(int min, int max, int value)
  7. range(int n)
  8. range(int start, int end)
  9. range(int start, int end)