Java Iterable Count count(Iterable i)

Here you can find the source of count(Iterable i)

Description

count

License

LGPL

Declaration

public static int count(Iterable<?> i) 

Method Source Code

//package com.java2s;
/**/*from  w  w  w .  ja  v a  2 s  .  c  o  m*/
 * Copyright 2009-2016 Three Crickets LLC.
 * <p>
 * The contents of this file are subject to the terms of the LGPL version 3.0:
 * http://www.gnu.org/copyleft/lesser.html
 * <p>
 * Alternatively, you can obtain a royalty free commercial license with less
 * limitations, transferable or non-transferable, directly from Three Crickets
 * at http://threecrickets.com
 */

import java.util.Iterator;

public class Main {
    public static int count(Iterable<?> i) {
        int count = 0;
        Iterator<?> ii = i.iterator();
        while (ii.hasNext()) {
            ii.next();
            count++;
        }
        return count;
    }
}

Related

  1. count(final Iterable iterable, final int step)
  2. count(Iterable iterable)
  3. count(Iterable iterable)
  4. count(Iterable iterable)