Java tutorial
//package com.java2s; import java.util.*; public class Main { /** * Nullsafe method returning the number of elements the incoming collection contains. * * @param c Collection of Objects to count the number of elements from * @return int containing the number of the elements in the collection, or -1 if the collection is null */ public static int size(Collection c) { int size = -1; if (c != null) { size = c.size(); } return size; } /** * Nullsafe method returning the number of entries the incoming map contains. * * @param m Map of Map.Entry objects to count the number of entries from * @return int containing the number of the entries in the map, or -1 if the map is null */ public static int size(Map m) { int size = -1; if (m != null) { size = m.size(); } return size; } }