Created
July 14, 2021 07:42
-
-
Save puke3615/3deff4315febd32bfc257801dbf64f7e to your computer and use it in GitHub Desktop.
CollectionUtil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Collection; | |
import java.util.Iterator; | |
/** | |
* @author puke | |
* @version 2021/5/10 | |
*/ | |
public class CollectionUtil { | |
public static <T> T getFirst(Collection<T> collection) { | |
if (collection == null) { | |
return null; | |
} else { | |
Iterator<T> iterator = collection.iterator(); | |
return iterator.hasNext() ? iterator.next() : null; | |
} | |
} | |
public static <T> boolean isNotEmpty(Collection<T> collection) { | |
return !isEmpty(collection); | |
} | |
public static <T> boolean isEmpty(Collection<T> collection) { | |
return collection == null || collection.isEmpty(); | |
} | |
public static <T> int size(Collection<T> collection) { | |
return collection == null ? 0 : collection.size(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment