Java Collection First sub(Collection coll, int first, int size)

Here you can find the source of sub(Collection coll, int first, int size)

Description

sub

License

MIT License

Declaration

public static Collection sub(Collection coll, int first, int size) 

Method Source Code

//package com.java2s;
/**/*from   ww  w .j a  v  a2 s . c o  m*/
 * Copyright (c) 2004-2011 Wang Jinbao(Julian Wong), http://www.ralasafe.com
 * Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
 */

import java.util.ArrayList;

import java.util.Collection;

import java.util.Iterator;

import java.util.List;

public class Main {
    public static Collection sub(Collection coll, int first, int size) {
        if (coll == null) {
            return null;
        }

        if (coll.size() < size && first == 0) {
            return coll;
        } else {
            List sub = new ArrayList(size);

            int i = -1;
            int fetchsize = 0;
            for (Iterator iter = coll.iterator(); iter.hasNext();) {
                Object object = (Object) iter.next();
                i++;
                if (i < first) {
                    continue;
                }

                sub.add(object);
                fetchsize++;

                if (fetchsize == size) {
                    break;
                }
            }

            return sub;
        }
    }
}

Related

  1. getUnionSize(Collection firstCollection, Collection secondCollection)
  2. intersect(Collection firstSet, Collection secondSet)
  3. nullSafeFirstElement(Collection collection)
  4. removeFirst(Collection collection, int numToRemove)
  5. removeFirst(Collection c)
  6. subtract(Collection firstCollection, Collection secondCollection)
  7. union(Collection firstSet, Collection secondSet)