Get size of nullable Collection - Java java.util

Java examples for java.util:Collection Size

Description

Get size of nullable Collection

Demo Code


//package com.java2s;

import java.util.Collection;

public class Main {
    public static void main(String[] argv) {
        Collection collection = java.util.Arrays.asList("asdf",
                "java2s.com");
        System.out.println(size(collection));
    }//from  w  w w. j a  v  a  2s .c  o  m

    public static int size(Collection<? extends Object> collection) {
        if (collection == null) {
            return 0;
        }
        return collection.size();
    }
}

Related Tutorials