Here you can find the source of clear(final Collection> collection)
public static void clear(final Collection<?> collection)
//package com.java2s; /*// w w w. j a v a2s.c o m * Copyright (C) 2013 Marcius da Silva da Fonseca. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA */ import java.util.Collection; import java.util.Map; public class Main { public static void clear(final Collection<?> collection) { if (isNotEmpty(collection)) { collection.clear(); } } public static void clear(final Map<?, ?> map) { if (isNotEmpty(map)) { map.clear(); } } /** * Tells if a given collection is not null and has something. * * @param collection The collection to be evaluated. * @return {@code true} if the given map is not null and has something. */ public static boolean isNotEmpty(final Collection<?> collection) { return !isEmptyOrNull(collection); } /** * Tells if a given map is not null and has something. * * @param map The map to be evaluated. * @return {@code true} if the given map is not null and has something. */ public static boolean isNotEmpty(final Map<?, ?> map) { return !isEmptyOrNull(map); } /** * Tells if a given collection is null or empty. * * @param collection The collection to be evaluated. * @return {@code true} if the given collection is null or empty. */ public static boolean isEmptyOrNull(final Collection<?> collection) { return collection == null || collection.isEmpty(); } /** * Tells if a given map is null or empty. * * @param map The map to be evaluated. * @return {@code true} if the given map is null or empty. */ public static boolean isEmptyOrNull(final Map<?, ?> map) { return map == null || map.isEmpty(); } }