Class Lists
- java.lang.Object
-
- dk.cloudcreate.essentials.shared.collections.Lists
-
-
Constructor Summary
Constructors Constructor Description Lists()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Optional<T>first(List<T> list)Get the first element in a liststatic <T> Optional<T>last(List<T> list)Get the last element in a liststatic <T> Stream<Pair<Integer,T>>toIndexedStream(List<T> list)
-
-
-
Method Detail
-
toIndexedStream
public static <T> Stream<Pair<Integer,T>> 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")
- Type Parameters:
T- the type of list element- Parameters:
list- the list that's converted to an indexed stream- Returns:
- the indexed list
-
first
public static <T> Optional<T> first(List<T> list)
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
public static <T> Optional<T> last(List<T> list)
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
-
-