public static <T, R extends Collection<T>> R take(Iterable<T> iterable, int count, R targetCollection)
    {
        if (count < 0)
        {
            throw new IllegalArgumentException("Count must be greater than zero, but was: " + count);
        }

        int countCopy = count;
        Iterator<T> iterator = iterable.iterator();
        while (iterator.hasNext() && countCopy-- > 0)
        {
            targetCollection.add(iterator.next());
        }
        return targetCollection;
    }
public static < T , R extends Collection < T > > R take ( Iterable < T > iterable , int count , R targetCollection ) { if ( count < 0 ) { throw new IllegalArgumentException ( "Count must be greater than zero, but was: " + count ) ; } int countCopy = count ; Iterator < T > iterator = iterable . iterator ( ) ; while ( iterator . hasNext ( ) && countCopy -- > 0 ) { targetCollection . add ( iterator . next ( ) ) ; } return targetCollection ; }
@see Iterate#take(Iterable, int)