/** * Returns a {@code Collector} that accumulates the input elements into a * new {@code List}. There are no guarantees on the type, mutability, * serializability, or thread-safety of the {@code List} returned; if more * control over the returned {@code List} is required, use {@link #toCollection(Supplier)}. * * @param <T> the type of the input elements * @return a {@code Collector} which collects all the input elements into a * {@code List}, in encounter order */ public static <T> Collector<T, ?, List<T>> toList() { return new CollectorImpl<>(arrayListNew(), listAdd(), (left, right) -> { left.addAll(right); return left; }, CH_ID); }
/** * Returns a {@code Collector} that accumulates the input elements into a * new {@code List}. There are no guarantees on the type, mutability, * serializability, or thread-safety of the {@code List} returned; if more * control over the returned {@code List} is required, use {@link #toCollection(Supplier)}. * * @param <T> the type of the input elements * @return a {@code Collector} which collects all the input elements into a * {@code List}, in encounter order */ public static <T> Collector<T, ?, List<T>> toList() { return new CollectorImpl<>(arrayListNew(), listAdd(), (left, right) -> { left.addAll(right); return left; }, CH_ID); }
/** * Returns a {@code Collector} that accumulates the input elements into an * {@link Lists#of(Object[]) unmodifiable List} in encounter * order. The returned Collector disallows null values and will throw * {@code NullPointerException} if it is presented with a null value. * * @param <T> the type of the input elements * @return a {@code Collector} which collects all the input elements into an * <a href="../Lists.html#unmodifiable">unmodifiable List</a>, in encounter order * @since 10 */ @SuppressWarnings("unchecked") public static <T> Collector<T, ?, List<T>> toUnmodifiableList() { return new CollectorImpl<>(arrayListNew(), listAdd(), (left, right) -> { left.addAll(right); return left; }, list -> (List<T>) Lists.of(list.toArray()), CH_NOID); }
/** * Returns a {@code Collector} that accumulates the input elements into an * {@link Lists#of(Object[]) unmodifiable List} in encounter * order. The returned Collector disallows null values and will throw * {@code NullPointerException} if it is presented with a null value. * * @param <T> the type of the input elements * @return a {@code Collector} which collects all the input elements into an * <a href="../Lists.html#unmodifiable">unmodifiable List</a>, in encounter order * @since 10 */ @SuppressWarnings("unchecked") public static <T> Collector<T, ?, List<T>> toUnmodifiableList() { return new CollectorImpl<>(arrayListNew(), listAdd(), (left, right) -> { left.addAll(right); return left; }, list -> (List<T>) Lists.of(list.toArray()), CH_NOID); }