Java Number Range Create range(int from, int to)

Here you can find the source of range(int from, int to)

Description

Generates an array of integers in range from 'from' to 'to'-1;

License

Open Source License

Parameter

Parameter Description
from a parameter
to a parameter

Declaration

public static int[] range(int from, int to) 

Method Source Code

//package com.java2s;
/**//from   w  w w. ja v a  2s  .c  om
 * Get a short description of the licensing terms.
 */

public class Main {
    /**
     * Generates an array of integers in range from 'from' to 'to'-1;
     * 
     * @param from
     * @param to
     * @return
     */
    public static int[] range(int from, int to) {
        if (from > to) {
            throw new IllegalArgumentException(
                    String.format("Invalid 'from' (%d) and 'to' (%d) values.", from, to));
        }

        int count = to - from;
        int[] r = new int[count];

        for (int i = 0; i < count; i++) {
            r[i] = from;
            from++;
        }

        return r;
    }
}

Related

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