集册 Java实例教程 返回iterable的大小;如果为null,则返回0

返回iterable的大小;如果为null,则返回0

欢马劈雪     最近更新时间:2020-01-02 10:19:05

622
返回iterable的大小,如果为空则返回0
/** from N o w J a v a . c o m**/

/*******************************************************************************

 * Copyright (c) 2014 Open Door Logistics (www.opendoorlogistics.com)

 * All rights reserved. This program and the accompanying materials

 * are made available under the terms of the GNU Lesser Public License v3

 * which accompanies this distribution, and is available at http://www.gnu.org/licenses/lgpl.txt

 ******************************************************************************/

//package com.nowjava;


public class Main {

    /**

     * Return the size of the iterable or 0 if its null

     * @param iterable

     * @return

     */

    public static int size(Iterable<?> iterable) {

        if (iterable == null) {

            return 0;

        }

        int count = 0;

        
展开阅读全文