get Collection Size - Java java.util

Java examples for java.util:Collection Attribute

Description

get Collection Size

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(getSize(collection));
    }/*  w  ww. j av a2 s.  c  o  m*/

    public static int getSize(Collection<?> collection) {
        return collection == null ? 0 : collection.size();
    }
}

Related Tutorials