Java tutorial
//package com.java2s; /** * Aptana Studio * Copyright (c) 2005-2011 by Appcelerator, Inc. All Rights Reserved. * Licensed under the terms of the GNU Public License (GPL) v3 (with exceptions). * Please see the license.html included with this distribution for details. * Any modifications to this file must keep this entire header intact. */ import java.util.Collection; import java.util.List; import java.util.Map; public class Main { /** * This is a convenience method to return the first element from a list. If the list is empty, then null is * returned. * * @param list * @return */ public static <T> T getFirstElement(List<T> list) { if (!isEmpty(list)) { return list.get(0); } return null; } /** * This is a convenience method that returns true if the specified collection is null or empty * * @param <T> * Any type of object * @param collection * @return */ public static <T> boolean isEmpty(Collection<T> collection) { return collection == null || collection.isEmpty(); } /** * This is a convenience method that returns true if the specified map is null or empty * * @param <T> * any type of key * @param <U> * any type of value * @param map * @return */ public static <T, U> boolean isEmpty(Map<T, U> map) { return map == null || map.isEmpty(); } }