Here you can find the source of addRange(Collection
Parameter | Description |
---|---|
c | the collection to add to |
start | the first value to add, inclusive |
to | the last value to add, exclusive |
step | the step size. |
Parameter | Description |
---|---|
RuntimeException | if the step size is zero or negative. |
public static void addRange(Collection<Integer> c, int start, int to, int step)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /**/*from w w w . j a v a 2 s . c om*/ * Adds values into the given collection using integer in the specified range and step size. * If the <tt>start</tt> value is greater or equal to the <tt>to</tt> value, nothing will * be added to the collection. * * @param c the collection to add to * @param start the first value to add, inclusive * @param to the last value to add, exclusive * @param step the step size. * @throws RuntimeException if the step size is zero or negative. */ public static void addRange(Collection<Integer> c, int start, int to, int step) { if (step <= 0) throw new RuntimeException("Would create an infinite loop"); for (int i = start; i < to; i += step) c.add(i); } }