Class Lists
java.lang.Object
dk.cloudcreate.essentials.shared.collections.Lists
List utility methods-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Optional<T>Get the first element in a liststatic <T> Optional<T>Get the last element in a liststatic <T> List<T>nullSafeList(List<T> list) toIndexedStream(List<T> list) Convert thelistto an 0-based Indexed Stream consisting ofPair's, where eachPairconsists of the 0-based Index (i.e. the first index has value 0) and the corresponding List element at the given index:Pair<Index, List-element-at-the-given-index>
Example:
List.of("A", "B", "C") will return aStreamof: Pair(0, "A") Pair(1, "B") Pair(2, "C")
-
Constructor Details
-
Lists
public Lists()
-
-
Method Details
-
toIndexedStream
Convert thelistto an 0-based Indexed Stream consisting ofPair's, where eachPairconsists of the 0-based Index (i.e. the first index has value 0) and the corresponding List element at the given index:Pair<Index, List-element-at-the-given-index>
Example:
List.of("A", "B", "C") will return aStreamof:- Pair(0, "A")
- Pair(1, "B")
- Pair(2, "C")
- Type Parameters:
T- the type of list element- Parameters:
list- the list that's converted to an indexed stream- Returns:
- the indexed list
-
first
Get the first element in a list- Type Parameters:
T- the type of elements in the list- Parameters:
list- the non-null list- Returns:
- the first element wrapped in an
OptionalorOptional.empty()if the list is empty
-
last
Get the last element in a list- Type Parameters:
T- the type of elements in the list- Parameters:
list- the non-null list- Returns:
- the last element wrapped in an
OptionalorOptional.empty()if the list is empty
-
nullSafeList
-