get List Size - Java java.util

Java examples for java.util:List Operation

Description

get List Size

Demo Code


//package com.java2s;

import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] argv) {
        List list = java.util.Arrays.asList("asdf", "java2s.com");
        System.out.println(getSize(list));
    }/*from ww w .ja  v a  2 s .c o  m*/

    public static <T> int getSize(List<T> list) {
        int size = 0;

        if (isEmpty(list)) {
            size = 0;
        } else {
            size = list.size();
        }

        return size;
    }

    public static <T> boolean isEmpty(List<T> list) {
        return list == null || list.isEmpty();
    }

    public static <K, V> boolean isEmpty(Map<K, V> map) {
        return map == null || map.isEmpty();
    }
}

Related Tutorials