Java tutorial
//package com.java2s; /******************************************************************************* * Copyright (c) 2010 Robert "Unlogic" Olofsson (unlogic@unlogic.se). * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Lesser Public License v3 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/lgpl-3.0-standalone.html ******************************************************************************/ import java.util.Collection; public class Main { /** * @param list * @return the size of the collection or 0 if the collection is null */ public static int getSize(Collection<?> collection) { if (collection == null) { return 0; } return collection.size(); } }