Java Collection Add addRange(Collection c, int start, int to, int step)

Here you can find the source of addRange(Collection c, int start, int to, int step)

Description

Adds values into the given collection using integer in the specified range and step size.

License

Open Source License

Parameter

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.

Exception

Parameter Description
RuntimeException if the step size is zero or negative.

Declaration

public static void addRange(Collection<Integer> c, int start, int to, int step) 

Method Source Code

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

Related

  1. addNonNulls(Collection c, X... xl)
  2. addNotNull(Collection col, String toAdd)
  3. addOneValueUNSAFE(Collection cloneCollection, Object v)
  4. addPrefix(Collection values, String prefix)
  5. addPreviousTags(int index, String[] prevTags, int prevTagsToAdd, Collection targetCol)
  6. addSafe(final Collection collection, T element)
  7. addTo(Collection l, Object... os)
  8. addTo(E element, C collection)
  9. addTo(Map> map, K key, V value)