Java Iterable Size size(Iterable it)

Here you can find the source of size(Iterable it)

Description

Count statements in iterable 'it'

License

BSD License

Parameter

Parameter Description
it the iterable

Return

the size

Declaration

public static int size(Iterable<?> it) 

Method Source Code

//package com.java2s;
/**//from  www .  j a  va2 s . c  om
 * LICENSE INFORMATION
 * 
 * Copyright 2005-2008 by FZI (http://www.fzi.de). Licensed under a BSD license
 * (http://www.opensource.org/licenses/bsd-license.php) <OWNER> = Max V?lkel
 * <ORGANIZATION> = FZI Forschungszentrum Informatik Karlsruhe, Karlsruhe,
 * Germany <YEAR> = 2010
 * 
 * Further project information at http://semanticweb.org/wiki/RDF2Go
 */

import java.util.Iterator;

public class Main {
    /**
     * Count statements in iterable 'it'
     * 
     * @param it the iterable
     * @return the size
     */
    public static int size(Iterable<?> it) {
        int count = 0;
        Iterator<?> i = it.iterator();
        while (i.hasNext()) {
            i.next();
            count++;
        }
        return count;
    }

    /**
     * Count statements in iterator 'it'
     * 
     * @param i the iterator
     * @return the size
     */
    public static int size(Iterator<?> i) {
        int count = 0;
        while (i.hasNext()) {
            i.next();
            count++;
        }
        return count;
    }
}

Related

  1. iterableSizeEq(Iterable itrbl, int k)
  2. singleOrNull(Iterable iterable)
  3. singleOrNull(Iterable iterable)
  4. size(final Iterable iterable)
  5. size(final Iterable iterable)
  6. size(Iterable iterable)
  7. size(Iterable values)
  8. sizeEquals(Iterable iterable, int expectedSize)