Java tutorial
//package com.java2s; import java.util.Collection; import java.util.Map; public class Main { public static int size(Collection<?> coll) { return isEmpty(coll) ? 0 : coll.size(); } public static int size(Map map) { return isEmpty(map) ? 0 : map.size(); } public static <T> int size(T[] arr) { return isEmpty(arr) ? 0 : arr.length; } public static boolean isEmpty(Collection<?> coll) { return coll == null || coll.isEmpty(); } public static <T> boolean isEmpty(T[] arr) { return arr == null || arr.length == 0; } public static boolean isEmpty(Map map) { return map == null || map.isEmpty(); } }