Package dev.prozilla.pine.common.util
Class ListUtils
java.lang.Object
dev.prozilla.pine.common.util.ListUtils
Utility methods related to lists.
Some methods only work for lists, others work for all instances of a super class of List, like Collection or even Iterable.
They are grouped together here for convenience.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> List<E> createSingleton(E element) static <E> EFinds the first element in a list that matches a predicate.static <E> EReturns the first element in a list, ornullif the list is empty.static <E,T extends E>
TgetInstance(Collection<E> list, Class<T> type) Finds the first element in a list of a given type.
-
Method Details
-
createSingleton
-
getInstance
Finds the first element in a list of a given type.This method is not suitable for frequent usage or usage with large lists.
- Type Parameters:
E- The type of elements in the listT- The type of element to search for- Parameters:
list- The list to search intype- The type to search for- Returns:
- The element of the given type, or
nullif there is none.
-
getFirst
Returns the first element in a list, ornullif the list is empty.- Type Parameters:
E- The type of elements in the list- Parameters:
list- The list- Returns:
- The first element or
null.
-
find
Finds the first element in a list that matches a predicate.- Type Parameters:
E- The type of elements in the list- Parameters:
list- The listpredicate- The predicate the element must match- Returns:
- The first element that matches the predicate, or
nullif there was none.
-