Java Iterable Size sizeEquals(Iterable iterable, int expectedSize)

Here you can find the source of sizeEquals(Iterable iterable, int expectedSize)

Description

size Equals

License

Open Source License

Declaration

public static <T> boolean sizeEquals(Iterable<T> iterable, int expectedSize) 

Method Source Code


//package com.java2s;
/*//from   w w  w. j  a  v  a2  s  . c o m
 * Copyright (c) Microsoft. All rights reserved.
 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
 */

import java.util.Iterator;

public class Main {
    public static <T> boolean sizeEquals(Iterable<T> iterable, int expectedSize) {
        Iterator<T> iterator = iterable.iterator();

        int currentSize = 0;
        while (iterator.hasNext()) {
            if (expectedSize > currentSize) {
                currentSize++;
                iterator.next();
                continue;
            } else {
                return false;
            }
        }

        return true;
    }
}

Related

  1. size(final Iterable iterable)
  2. size(final Iterable iterable)
  3. size(Iterable it)
  4. size(Iterable iterable)
  5. size(Iterable values)