Class CharStream

java.lang.Object
com.landawn.abacus.util.stream.CharStream
All Implemented Interfaces:
Immutable, BaseStream<Character,char[],CharPredicate,CharConsumer,CharList,u.OptionalChar,IndexedChar,CharIterator,CharStream>, Closeable, AutoCloseable
Direct Known Subclasses:
CharStream.CharStreamEx

@Immutable public abstract class CharStream extends Object
The Stream will be automatically closed after execution(A terminal method is executed/triggered).
See Also:
  • Method Details

    • rateLimited

      public CharStream rateLimited(RateLimiter rateLimiter)
      Returns:
      See Also:
    • delay

      public CharStream delay(Duration delay)
      Returns:
    • skipUntil

      public CharStream skipUntil(CharPredicate predicate)
      Returns:
      See Also:
    • map

      Returns a stream consisting of the results of applying the given function to the elements of this stream.

      This is an intermediate operation.

      Parameters:
      mapper - a non-interfering, stateless function to apply to each element
      Returns:
    • mapToInt

      Returns a IntStream consisting of the results of applying the given function to the elements of this stream.

      This is an intermediate operation.

      Parameters:
      mapper - a non-interfering, stateless function to apply to each element
      Returns:
    • mapToObj

      @ParallelSupported @IntermediateOp public abstract <T> Stream<T> mapToObj(CharFunction<? extends T> mapper)
      Returns an object-valued Stream consisting of the results of applying the given function to the elements of this stream.

      This is an intermediate operation.

      Type Parameters:
      T - the element type of the new stream
      Parameters:
      mapper - a non-interfering, stateless function to apply to each element
      Returns:
    • flatMap

      @ParallelSupported @IntermediateOp public abstract CharStream flatMap(CharFunction<? extends CharStream> mapper)
      Returns a stream consisting of the results of replacing each element of this stream with the contents of a mapped stream produced by applying the provided mapping function to each element.

      This is an intermediate operation.

      Parameters:
      mapper - a non-interfering, stateless function to apply to each element which produces an CharStream of new values
      Returns:
      See Also:
    • flatmap

      @ParallelSupported @IntermediateOp public abstract CharStream flatmap(CharFunction<char[]> mapper)
    • flatMapToInt

      @ParallelSupported @IntermediateOp public abstract IntStream flatMapToInt(CharFunction<? extends IntStream> mapper)
    • flatMapToObj

      @ParallelSupported @IntermediateOp public abstract <T> Stream<T> flatMapToObj(CharFunction<? extends Stream<? extends T>> mapper)
    • flatmapToObj

      @ParallelSupported @IntermediateOp public abstract <T> Stream<T> flatmapToObj(CharFunction<? extends Collection<? extends T>> mapper)
    • flattMapToObj

      @ParallelSupported @IntermediateOp public abstract <T> Stream<T> flattMapToObj(CharFunction<T[]> mapper)
    • mapPartial

      Note: copied from StreamEx: https://github.com/amaembo/streamex
      Type Parameters:
      R -
      Parameters:
      mapper -
      Returns:
    • rangeMap

      @SequentialOnly @IntermediateOp public abstract CharStream rangeMap(CharBiPredicate sameRange, CharBinaryOperator mapper)
      Note: copied from StreamEx: https://github.com/amaembo/streamex
      Returns a stream consisting of results of applying the given function to the ranges created from the source elements. This is a quasi-intermediate partial reduction operation.
      Parameters:
      sameRange - a non-interfering, stateless predicate to apply to the leftmost and next elements which returns true for elements which belong to the same range.
      mapper - a non-interfering, stateless function to apply to the range borders and produce the resulting element. If value was not merged to the interval, then mapper will receive the same value twice, otherwise it will receive the leftmost and the rightmost values which were merged to the range.
      Returns:
      See Also:
    • rangeMapToObj

      @SequentialOnly @IntermediateOp public abstract <T> Stream<T> rangeMapToObj(CharBiPredicate sameRange, CharBiFunction<? extends T> mapper)
      Note: copied from StreamEx: https://github.com/amaembo/streamex
      Returns a stream consisting of results of applying the given function to the ranges created from the source elements. This is a quasi-intermediate partial reduction operation.
      Parameters:
      sameRange - a non-interfering, stateless predicate to apply to the leftmost and next elements which returns true for elements which belong to the same range.
      mapper - a non-interfering, stateless function to apply to the range borders and produce the resulting element. If value was not merged to the interval, then mapper will receive the same value twice, otherwise it will receive the leftmost and the rightmost values which were merged to the range.
      Returns:
      See Also:
    • collapse

      @SequentialOnly @IntermediateOp public abstract Stream<CharList> collapse(CharBiPredicate collapsible)
      Merge series of adjacent elements which satisfy the given predicate using the merger function and return a new stream.
      This method only runs sequentially, even in parallel stream.
      Parameters:
      collapsible -
      Returns:
    • collapse

      @SequentialOnly @IntermediateOp public abstract CharStream collapse(CharBiPredicate collapsible, CharBinaryOperator mergeFunction)
      Merge series of adjacent elements which satisfy the given predicate using the merger function and return a new stream.
      This method only runs sequentially, even in parallel stream.
      Parameters:
      collapsible -
      mergeFunction -
      Returns:
    • collapse

      @SequentialOnly @IntermediateOp public abstract CharStream collapse(CharTriPredicate collapsible, CharBinaryOperator mergeFunction)
      Parameters:
      collapsible - test the current element with the first element and previous element in the series. The first parameter is the first element of this series, the second parameter is the previous element and the third parameter is the current element.
      mergeFunction -
      Returns:
    • scan

      @SequentialOnly @IntermediateOp public abstract CharStream scan(CharBinaryOperator accumulator)
      Returns a Stream produced by iterative application of a accumulation function to an initial element init and next element of the current stream. Produces a Stream consisting of init, acc(init, value1), acc(acc(init, value1), value2), etc.

      This is an intermediate operation.

      Example:

       accumulator: (a, b) -> a + b
       stream: [1, 2, 3, 4, 5]
       result: [1, 3, 6, 10, 15]
       

      This method only runs sequentially, even in parallel stream.
      Parameters:
      accumulator - the accumulation function
      Returns:
    • scan

      @SequentialOnly @IntermediateOp public abstract CharStream scan(char init, CharBinaryOperator accumulator)
      Returns a Stream produced by iterative application of a accumulation function to an initial element init and next element of the current stream. Produces a Stream consisting of init, acc(init, value1), acc(acc(init, value1), value2), etc.

      This is an intermediate operation.

      Example:

       init:10
       accumulator: (a, b) -> a + b
       stream: [1, 2, 3, 4, 5]
       result: [11, 13, 16, 20, 25]
       

      This method only runs sequentially, even in parallel stream.
      Parameters:
      init - the initial value. it's only used once by accumulator to calculate the fist element in the returned stream. It will be ignored if this stream is empty and won't be the first element of the returned stream.
      accumulator - the accumulation function
      Returns:
    • scan

      @SequentialOnly @IntermediateOp public abstract CharStream scan(char init, CharBinaryOperator accumulator, boolean initIncluded)
      Parameters:
      init -
      accumulator -
      initIncluded -
      Returns:
    • prepend

      @SequentialOnly @IntermediateOp public abstract CharStream prepend(char... a)
    • append

      @SequentialOnly @IntermediateOp public abstract CharStream append(char... a)
    • appendIfEmpty

      @SequentialOnly @IntermediateOp public abstract CharStream appendIfEmpty(char... a)
    • toCharList

      @SequentialOnly @TerminalOp public abstract CharList toCharList()
    • toMap

      @ParallelSupported @TerminalOp public abstract <K, V, E extends Exception, E2 extends Exception> Map<K,V> toMap(Throwables.CharFunction<? extends K,E> keyMapper, Throwables.CharFunction<? extends V,E2> valueMapper) throws E, E2
      Parameters:
      keyMapper -
      valueMapper -
      Returns:
      Throws:
      E extends Exception
      E2 extends Exception
      See Also:
      • Collectors#toMap(Throwables.Function, Throwables.Function)
    • toMap

      @ParallelSupported @TerminalOp public abstract <K, V, M extends Map<K, V>, E extends Exception, E2 extends Exception> M toMap(Throwables.CharFunction<? extends K,E> keyMapper, Throwables.CharFunction<? extends V,E2> valueMapper, Supplier<? extends M> mapFactory) throws E, E2
      Parameters:
      keyMapper -
      valueMapper -
      mapFactory -
      Returns:
      Throws:
      E extends Exception
      E2 extends Exception
      See Also:
      • Collectors#toMap(Throwables.Function, Throwables.Function, Supplier)
    • toMap

      @ParallelSupported @TerminalOp public abstract <K, V, E extends Exception, E2 extends Exception> Map<K,V> toMap(Throwables.CharFunction<? extends K,E> keyMapper, Throwables.CharFunction<? extends V,E2> valueMapper, BinaryOperator<V> mergeFunction) throws E, E2
      Parameters:
      keyMapper -
      valueMapper -
      mergeFunction -
      Returns:
      Throws:
      E extends Exception
      E2 extends Exception
      See Also:
      • Collectors#toMap(Throwables.Function, Throwables.Function, BinaryOperator)
    • toMap

      @ParallelSupported @TerminalOp public abstract <K, V, M extends Map<K, V>, E extends Exception, E2 extends Exception> M toMap(Throwables.CharFunction<? extends K,E> keyMapper, Throwables.CharFunction<? extends V,E2> valueMapper, BinaryOperator<V> mergeFunction, Supplier<? extends M> mapFactory) throws E, E2
      Parameters:
      keyMapper -
      valueMapper -
      mergeFunction -
      mapFactory -
      Returns:
      Throws:
      E extends Exception
      E2 extends Exception
      See Also:
      • Collectors#toMap(Throwables.Function, Throwables.Function, BinaryOperator, Supplier)
    • groupTo

      @ParallelSupported @TerminalOp public abstract <K, D, E extends Exception> Map<K,D> groupTo(Throwables.CharFunction<? extends K,E> keyMapper, Collector<? super Character,?,D> downstream) throws E
      Parameters:
      keyMapper -
      downstream -
      Returns:
      Throws:
      E extends Exception
      See Also:
      • Collectors#groupingBy(Throwables.Function, Collector)
    • groupTo

      @ParallelSupported @TerminalOp public abstract <K, D, M extends Map<K, D>, E extends Exception> M groupTo(Throwables.CharFunction<? extends K,E> keyMapper, Collector<? super Character,?,D> downstream, Supplier<? extends M> mapFactory) throws E
      Parameters:
      keyMapper -
      downstream -
      mapFactory -
      Returns:
      Throws:
      E extends Exception
      See Also:
      • Collectors#groupingBy(Throwables.Function, Collector, Supplier)
    • reduce

      @ParallelSupported @TerminalOp public abstract char reduce(char identity, CharBinaryOperator op)
      Parameters:
      identity -
      op -
      Returns:
    • reduce

      Parameters:
      op -
      Returns:
    • collect

      @ParallelSupported @TerminalOp public abstract <R> R collect(Supplier<R> supplier, ObjCharConsumer<? super R> accumulator, BiConsumer<R,R> combiner)
      Type Parameters:
      R -
      Parameters:
      supplier -
      accumulator -
      combiner -
      Returns:
      See Also:
    • collect

      @ParallelSupported @TerminalOp public abstract <R> R collect(Supplier<R> supplier, ObjCharConsumer<? super R> accumulator)
      Only call this method when the returned type R is one types: Collection/Map/StringBuilder/Multiset/LongMultiset/Multimap/BooleanList/IntList/.../DoubleList. Otherwise, please call collect(Supplier, ObjCharConsumer, BiConsumer).
      Parameters:
      supplier -
      accumulator -
      Returns:
      See Also:
    • forEach

      @ParallelSupported @TerminalOp public abstract <E extends Exception> void forEach(Throwables.CharConsumer<E> action) throws E
      Throws:
      E extends Exception
    • forEachIndexed

      @ParallelSupported @TerminalOp public abstract <E extends Exception> void forEachIndexed(Throwables.IndexedCharConsumer<E> action) throws E
      Throws:
      E extends Exception
    • anyMatch

      @ParallelSupported @TerminalOp public abstract <E extends Exception> boolean anyMatch(Throwables.CharPredicate<E> predicate) throws E
      Throws:
      E extends Exception
    • allMatch

      @ParallelSupported @TerminalOp public abstract <E extends Exception> boolean allMatch(Throwables.CharPredicate<E> predicate) throws E
      Throws:
      E extends Exception
    • noneMatch

      @ParallelSupported @TerminalOp public abstract <E extends Exception> boolean noneMatch(Throwables.CharPredicate<E> predicate) throws E
      Throws:
      E extends Exception
    • findFirst

      @ParallelSupported @TerminalOp public abstract <E extends Exception> u.OptionalChar findFirst(Throwables.CharPredicate<E> predicate) throws E
      Throws:
      E extends Exception
    • findFirstOrAny

      @ParallelSupported @TerminalOp public abstract <E extends Exception> u.OptionalChar findFirstOrAny(Throwables.CharPredicate<E> predicateForFirst) throws E
      Returns the first element matched by predicateForFirst if found or the first element if this stream is not empty Otherwise an empty OptionalChar will be returned.
      Type Parameters:
      E -
      Parameters:
      predicateForFirst -
      Returns:
      Throws:
      E
    • findFirstOrLast

      @ParallelSupported @TerminalOp public abstract <E extends Exception> u.OptionalChar findFirstOrLast(Throwables.CharPredicate<E> predicateForFirst) throws E
      Returns the first element matched by predicateForFirst if found or the last element if this stream is not empty Otherwise an empty OptionalChar will be returned.
      Type Parameters:
      E -
      Parameters:
      predicateForFirst -
      Returns:
      Throws:
      E
    • findLast

      @ParallelSupported @TerminalOp public abstract <E extends Exception> u.OptionalChar findLast(Throwables.CharPredicate<E> predicate) throws E
      Consider using: stream.reversed().findFirst(predicate) for better performance if possible.
      Type Parameters:
      E -
      Parameters:
      predicate -
      Returns:
      Throws:
      E
    • findAny

      @ParallelSupported @TerminalOp public abstract <E extends Exception> u.OptionalChar findAny(Throwables.CharPredicate<E> predicate) throws E
      Throws:
      E extends Exception
    • min

      Returns an OptionalChar describing the minimum element of this stream, or an empty optional if this stream is empty. This is a special case of a reduction and is equivalent to:
      
           return reduce(Chareger::min);
       

      This is a terminal operation.

      Returns:
      an OptionalChar containing the minimum element of this stream, or an empty OptionalChar if the stream is empty
    • max

      Returns an OptionalChar describing the maximum element of this stream, or an empty optional if this stream is empty. This is a special case of a reduction and is equivalent to:
      
           return reduce(Chareger::max);
       

      This is a terminal operation.

      Returns:
      an OptionalChar containing the maximum element of this stream, or an empty OptionalChar if the stream is empty
    • kthLargest

      @SequentialOnly @TerminalOp public abstract u.OptionalChar kthLargest(int k)
      Parameters:
      k -
      Returns:
      OptionalByte.empty() if there is no element or count less than k, otherwise the kth largest element.
    • sum

      @SequentialOnly @TerminalOp public abstract int sum()
    • average

      @SequentialOnly @TerminalOp public abstract u.OptionalDouble average()
    • summarize

      @SequentialOnly @TerminalOp public abstract CharSummaryStatistics summarize()
    • summarizeAndPercentiles

    • mergeWith

      @SequentialOnly @IntermediateOp public abstract CharStream mergeWith(CharStream b, CharBiFunction<MergeResult> nextSelector)
      Parameters:
      b -
      nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.
      Returns:
    • zipWith

      @ParallelSupported @IntermediateOp public abstract CharStream zipWith(CharStream b, CharBinaryOperator zipFunction)
    • zipWith

    • zipWith

      @ParallelSupported @IntermediateOp public abstract CharStream zipWith(CharStream b, char valueForNoneA, char valueForNoneB, CharBinaryOperator zipFunction)
    • zipWith

      @ParallelSupported @IntermediateOp public abstract CharStream zipWith(CharStream b, CharStream c, char valueForNoneA, char valueForNoneB, char valueForNoneC, CharTernaryOperator zipFunction)
    • asIntStream

      @SequentialOnly @IntermediateOp public abstract IntStream asIntStream()
      Returns a LongStream consisting of the elements of this stream, converted to long.

      This is an intermediate operation.

      Returns:
      a LongStream consisting of the elements of this stream, converted to long
    • boxed

      @SequentialOnly @IntermediateOp public abstract Stream<Character> boxed()
      Returns a Stream consisting of the elements of this stream, each boxed to an Chareger.

      This is an intermediate operation.

      Returns:
      a Stream consistent of the elements of this stream, each boxed to an Chareger
    • iterator

      public CharIterator iterator()
      Remember to close this Stream after the iteration is done, if needed.
      Returns:
    • empty

      public static CharStream empty()
    • ofNullable

      public static CharStream ofNullable(Character e)
    • of

      @SafeVarargs public static CharStream of(char... a)
    • of

      public static CharStream of(char[] a, int startIndex, int endIndex)
    • of

      public static CharStream of(CharSequence str)
      Takes the chars in the specified String as the elements of the Stream
      Parameters:
      str -
      Returns:
    • of

      public static CharStream of(CharSequence str, int startIndex, int endIndex)
      Takes the chars in the specified String as the elements of the Stream
      Parameters:
      str -
      startIndex -
      endIndex -
      Returns:
    • of

      public static CharStream of(Character[] a)
    • of

      public static CharStream of(Character[] a, int startIndex, int endIndex)
    • of

      public static CharStream of(Collection<Character> c)
    • of

      public static CharStream of(CharIterator iterator)
    • of

      public static CharStream of(CharBuffer buf)
    • of

      public static CharStream of(File file)
    • of

      public static CharStream of(Reader reader)
    • of

      public static CharStream of(Reader reader, boolean closeReaderAferExecution)
    • defer

      public static CharStream defer(Supplier<CharStream> supplier)
      Lazy evaluation.
      This is equal to: Stream.just(supplier).flatMapToChar(it -> it.get()).
      Type Parameters:
      T -
      Parameters:
      supplier -
      Returns:
    • flatten

      public static CharStream flatten(char[][] a)
    • flatten

      public static CharStream flatten(char[][] a, boolean vertically)
    • flatten

      public static CharStream flatten(char[][] a, char valueForNone, boolean vertically)
    • flatten

      public static CharStream flatten(char[][][] a)
    • range

      public static CharStream range(char startInclusive, char endExclusive)
    • range

      public static CharStream range(char startInclusive, char endExclusive, int by)
    • rangeClosed

      public static CharStream rangeClosed(char startInclusive, char endInclusive)
    • rangeClosed

      public static CharStream rangeClosed(char startInclusive, char endInclusive, int by)
    • repeat

      public static CharStream repeat(char element, long n)
    • random

      public static CharStream random()
    • random

      public static CharStream random(char startInclusive, char endExclusive)
    • random

      public static CharStream random(char[] candicates)
    • iterate

      public static CharStream iterate(BooleanSupplier hasNext, CharSupplier next)
    • iterate

      public static CharStream iterate(char init, BooleanSupplier hasNext, CharUnaryOperator f)
    • iterate

      public static CharStream iterate(char init, CharPredicate hasNext, CharUnaryOperator f)
      Parameters:
      init -
      hasNext - test if has next by hasNext.test(init) for first time and hasNext.test(f.apply(previous)) for remaining.
      f -
      Returns:
    • iterate

      public static CharStream iterate(char init, CharUnaryOperator f)
    • generate

      public static CharStream generate(CharSupplier s)
    • concat

      @SafeVarargs public static CharStream concat(char[]... a)
    • concat

      @SafeVarargs public static CharStream concat(CharIterator... a)
    • concat

      @SafeVarargs public static CharStream concat(CharStream... a)
    • concat

      @Beta public static CharStream concat(List<char[]> c)
    • concat

      public static CharStream concat(Collection<? extends CharStream> c)
    • concatIterators

      @Beta public static CharStream concatIterators(Collection<? extends CharIterator> c)
    • zip

      public static CharStream zip(char[] a, char[] b, CharBinaryOperator zipFunction)
      Zip together the "a" and "b" arrays until one of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      Returns:
    • zip

      public static CharStream zip(char[] a, char[] b, char[] c, CharTernaryOperator zipFunction)
      Zip together the "a", "b" and "c" arrays until one of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      c -
      Returns:
    • zip

      public static CharStream zip(CharIterator a, CharIterator b, CharBinaryOperator zipFunction)
      Zip together the "a" and "b" iterators until one of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      Returns:
    • zip

      public static CharStream zip(CharIterator a, CharIterator b, CharIterator c, CharTernaryOperator zipFunction)
      Zip together the "a", "b" and "c" iterators until one of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      Returns:
    • zip

      public static CharStream zip(CharStream a, CharStream b, CharBinaryOperator zipFunction)
      Zip together the "a" and "b" streams until one of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      Returns:
    • zip

      public static CharStream zip(CharStream a, CharStream b, CharStream c, CharTernaryOperator zipFunction)
      Zip together the "a", "b" and "c" streams until one of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      Returns:
    • zip

      public static CharStream zip(Collection<? extends CharStream> c, CharNFunction<Character> zipFunction)
      Zip together the iterators until one of them runs out of values. Each array of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      c -
      zipFunction -
      Returns:
    • zip

      public static CharStream zip(char[] a, char[] b, char valueForNoneA, char valueForNoneB, CharBinaryOperator zipFunction)
      Zip together the "a" and "b" iterators until all of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      valueForNoneA - value to fill if "a" runs out of values first.
      valueForNoneB - value to fill if "b" runs out of values first.
      zipFunction -
      Returns:
    • zip

      public static CharStream zip(char[] a, char[] b, char[] c, char valueForNoneA, char valueForNoneB, char valueForNoneC, CharTernaryOperator zipFunction)
      Zip together the "a", "b" and "c" iterators until all of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      c -
      valueForNoneA - value to fill if "a" runs out of values.
      valueForNoneB - value to fill if "b" runs out of values.
      valueForNoneC - value to fill if "c" runs out of values.
      zipFunction -
      Returns:
    • zip

      public static CharStream zip(CharIterator a, CharIterator b, char valueForNoneA, char valueForNoneB, CharBinaryOperator zipFunction)
      Zip together the "a" and "b" iterators until all of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      valueForNoneA - value to fill if "a" runs out of values first.
      valueForNoneB - value to fill if "b" runs out of values first.
      zipFunction -
      Returns:
    • zip

      public static CharStream zip(CharIterator a, CharIterator b, CharIterator c, char valueForNoneA, char valueForNoneB, char valueForNoneC, CharTernaryOperator zipFunction)
      Zip together the "a", "b" and "c" iterators until all of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      c -
      valueForNoneA - value to fill if "a" runs out of values.
      valueForNoneB - value to fill if "b" runs out of values.
      valueForNoneC - value to fill if "c" runs out of values.
      zipFunction -
      Returns:
    • zip

      public static CharStream zip(CharStream a, CharStream b, char valueForNoneA, char valueForNoneB, CharBinaryOperator zipFunction)
      Zip together the "a" and "b" iterators until all of them runs out of values. Each pair of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      valueForNoneA - value to fill if "a" runs out of values first.
      valueForNoneB - value to fill if "b" runs out of values first.
      zipFunction -
      Returns:
    • zip

      public static CharStream zip(CharStream a, CharStream b, CharStream c, char valueForNoneA, char valueForNoneB, char valueForNoneC, CharTernaryOperator zipFunction)
      Zip together the "a", "b" and "c" iterators until all of them runs out of values. Each triple of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      a -
      b -
      c -
      valueForNoneA - value to fill if "a" runs out of values.
      valueForNoneB - value to fill if "b" runs out of values.
      valueForNoneC - value to fill if "c" runs out of values.
      zipFunction -
      Returns:
    • zip

      public static CharStream zip(Collection<? extends CharStream> c, char[] valuesForNone, CharNFunction<Character> zipFunction)
      Zip together the iterators until all of them runs out of values. Each array of values is combined into a single value using the supplied zipFunction function.
      Parameters:
      c -
      valuesForNone - value to fill for any iterator runs out of values.
      zipFunction -
      Returns:
    • merge

      public static CharStream merge(char[] a, char[] b, CharBiFunction<MergeResult> nextSelector)
      Parameters:
      a -
      b -
      nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.
      Returns:
    • merge

      public static CharStream merge(char[] a, char[] b, char[] c, CharBiFunction<MergeResult> nextSelector)
      Parameters:
      a -
      b -
      c -
      nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.
      Returns:
    • merge

      public static CharStream merge(CharIterator a, CharIterator b, CharBiFunction<MergeResult> nextSelector)
      Parameters:
      a -
      b -
      nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.
      Returns:
    • merge

      public static CharStream merge(CharIterator a, CharIterator b, CharIterator c, CharBiFunction<MergeResult> nextSelector)
      Parameters:
      a -
      b -
      c -
      nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.
      Returns:
    • merge

      public static CharStream merge(CharStream a, CharStream b, CharBiFunction<MergeResult> nextSelector)
      Parameters:
      a -
      b -
      nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.
      Returns:
    • merge

      public static CharStream merge(CharStream a, CharStream b, CharStream c, CharBiFunction<MergeResult> nextSelector)
      Parameters:
      a -
      b -
      c -
      nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.
      Returns:
    • merge

      public static CharStream merge(Collection<? extends CharStream> c, CharBiFunction<MergeResult> nextSelector)
      Parameters:
      c -
      nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.
      Returns:
    • parallelMerge

      public static CharStream parallelMerge(Collection<? extends CharStream> c, CharBiFunction<MergeResult> nextSelector)
      All the elements from each input Collection/Iterator/Stream will be merged into two queues by multiple threads. Then these two new queues will be merged into one Iterator/Stream by one thread. So it's not totally lazy evaluation and may cause out of memory error if there are too many elements merged into the new queues. Consider using merge, which is totally lazy evaluation.
      Parameters:
      c -
      nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.
      Returns:
    • parallelMerge

      public static CharStream parallelMerge(Collection<? extends CharStream> c, CharBiFunction<MergeResult> nextSelector, int maxThreadNum)
      All the elements from each input Collection/Iterator/Stream will be merged into two queues by multiple threads. Then these two new queues will be merged into one Iterator/Stream by one thread. So it's not totally lazy evaluation and may cause out of memory error if there are too many elements merged into the new queues. Consider using merge, which is totally lazy evaluation.
      Parameters:
      c -
      nextSelector - first parameter is selected if Nth.FIRST is returned, otherwise the second parameter is selected.
      maxThreadNum -
      Returns:
    • elementAt

      public u.OptionalChar elementAt(long position)
      Specified by:
      elementAt in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      position -
      Returns:
    • rateLimited

      public CharStream rateLimited(double permitsPerSecond)
      Specified by:
      rateLimited in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      permitsPerSecond -
      Returns:
      See Also:
    • peek

      public CharStream peek(CharConsumer action)
      Specified by:
      peek in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      action -
      Returns:
    • sliding

      public Stream<CharStream> sliding(int windowSize)
      Specified by:
      sliding in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      windowSize -
      Returns:
      See Also:
    • slidingToList

      public Stream<CharList> slidingToList(int windowSize)
      Specified by:
      slidingToList in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      windowSize -
      Returns:
      See Also:
    • shuffled

      public CharStream shuffled()
      Description copied from interface: BaseStream

      This method only runs sequentially, even in parallel stream and all elements will be loaded to memory.
      Specified by:
      shuffled in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Returns:
    • throwIfEmpty

      @SequentialOnly @IntermediateOp public CharStream throwIfEmpty(Supplier<? extends RuntimeException> exceptionSupplier)
      Specified by:
      throwIfEmpty in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      exceptionSupplier -
      Returns:
    • toImmutableList

      public ImmutableList<Character> toImmutableList()
      Specified by:
      toImmutableList in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Returns:
    • toImmutableSet

      public ImmutableSet<Character> toImmutableSet()
      Specified by:
      toImmutableSet in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Returns:
    • join

      public String join(CharSequence delimiter)
      Specified by:
      join in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      delimiter -
      Returns:
    • println

      public void println()
      Specified by:
      println in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
    • transform

      public <SS extends BaseStream> SS transform(Function<? super CharStream,? extends SS> transfer)
      Specified by:
      transform in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Type Parameters:
      SS -
      Parameters:
      transfer -
      Returns:
    • __

      @Deprecated public <SS extends BaseStream> SS __(Function<? super CharStream,? extends SS> transfer)
      Deprecated.
      Specified by:
      __ in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Type Parameters:
      SS -
      Parameters:
      transfer -
      Returns:
    • isParallel

      public boolean isParallel()
      Specified by:
      isParallel in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Returns:
    • sequential

      public CharStream sequential()
      Specified by:
      sequential in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Returns:
    • parallel

      public CharStream parallel()
      Description copied from interface: BaseStream
      Consider using sps(Function) if only next operation need to be parallelized. For example:
       stream.parallel().map(f).filter(p)...;
      
       // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream.
       stream.sps(s -> s.map(f)).filter(p)...;
       // Or switch the stream back sequential stream if don't use "sps".
       stream.parallel().map(f).sequential().filter(p)...;
      
       
      In most scenarios, there could be only one operation need be parallelized in the stream. So sps(Function) is recommended in most of scenarios.
      Specified by:
      parallel in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Returns:
      See Also:
    • parallel

      public CharStream parallel(int maxThreadNum)
      Description copied from interface: BaseStream
      Consider using sps(int, Function) if only next operation need to be parallelized. For example:
       stream.parallel(maxThreadNum).map(f).filter(p)...;
      
       // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream.
       stream.sps(maxThreadNum, s -> s.map(f)).filter(p)...;
       // Or switch the stream back sequential stream if don't use "sps".
       stream.parallel(maxThreadNum).map(f).sequential().filter(p)...;
      
       
      In most scenarios, there could be only one operation need be parallelized in the stream. So sps(int, Function) is recommended in most of scenarios.
      Specified by:
      parallel in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      maxThreadNum -
      Returns:
      See Also:
      • #maxThreadNumPerOperation()
    • parallel

      public CharStream parallel(BaseStream.Splitor splitor)
      Specified by:
      parallel in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      splitor -
      Returns:
      See Also:
    • parallel

      public CharStream parallel(int maxThreadNum, BaseStream.Splitor splitor)
      Description copied from interface: BaseStream
      Returns an equivalent stream that is parallel. May return itself if the stream was already parallel with the same maxThreadNum and splitor as the specified ones.

      When to use parallel Streams?
       
       Profiler.run(1, 1, 3, "sequential", () -> Stream.of(list).operation(F)...).printResult();
       Profiler.run(1, 1, 3, "parallel", () -> Stream.of(list).parallel().operation(F)...).printResult();
       
       
      Here is a sample performance test with computer: CPU Intel i7-3520M 4-cores 2.9 GHz, JDK 1.8.0_101, Windows 7:
       
      
           public void test_perf() {
              final String[] strs = new String[10_000];
              N.fill(strs, N.uuid());
          
              final int m = 10;
              final Function<String, Long> mapper = str -> {
                  long result = 0;
                  for (int i = 0; i < m; i++) {
                      result += N.sum(str.toCharArray()) + 1;
                  }
                  return result;
              };
          
              final MutableLong sum = MutableLong.of(0);
          
              for (int i = 0, len = strs.length; i < len; i++) {
                  sum.add(mapper.apply(strs[i]));
              }
          
              final int threadNum = 1, loopNum = 100, roundNum = 3;
          
              Profiler.run(threadNum, loopNum, roundNum, "For Loop", () -> {
                  long result = 0;
                  for (int i = 0, len = strs.length; i < len; i++) {
                      result += mapper.apply(strs[i]);
                  }
                  assertEquals(sum.longValue(), result);
              }).printResult();
          
              Profiler.run(threadNum, loopNum, roundNum, "JDK Sequential",
                      () -> assertEquals(sum.longValue(), java.util.stream.Stream.of(strs).map(mapper).mapToLong(e -> e).sum())).printResult();
          
              Profiler.run(threadNum, loopNum, roundNum, "JDK Parallel",
                      () -> assertEquals(sum.longValue(), java.util.stream.Stream.of(strs).parallel().map(mapper).mapToLong(e -> e).sum())).printResult();
          
              Profiler.run(threadNum, loopNum, roundNum, "Abcus Sequential", () -> assertEquals(sum.longValue(), Stream.of(strs).map(mapper).mapToLong(e -> e).sum()))
                      .printResult();
          
              Profiler.run(threadNum, loopNum, roundNum, "Abcus Parallel",
                      () -> assertEquals(sum.longValue(), Stream.of(strs).parallel().map(mapper).mapToLong(e -> e).sum())).printResult();
          
              Profiler.run(threadNum, loopNum, roundNum, "Abcus Parallel by chunck", () -> assertEquals(sum.longValue(),
                      Stream.of(strs).splitToList(100).parallel().map(it -> N.sumLong(it, e -> mapper.apply(e))).mapToLong(e -> e).sum())).printResult();
           }
          
       
       
      And test result: Unit is milliseconds. N(the number of elements) is 10_000, Q(cost per element of F, the per-element function (usually a lambda), here is mapper) is calculated by: value of 'For loop' / N(10_000).
      m = 1 m = 10m = 50m = 100m = 500m = 1000
      Q 0.000020.00020.0010.0020.010.02
      For Loop0.232.31122110219
      JDK Sequential0.282.31122114212
      JDK Parallel0.221.361266122
      Abcus Sequential0.321122112212
      Abcus Parallel1111111677128
      Comparison:
      • Again, do NOT and should NOT use parallel Streams if you don't have any performance problem with sequential Streams, because using parallel Streams has extra cost.
      • Again, consider using parallel Streams only when N(the number of elements) * Q(cost per element of F, the per-element function (usually a lambda)) is big enough.
      • The implementation of parallel Streams in Abacus is more than 10 times, slower than parallel Streams in JDK when Q is tiny(here is less than 0.0002 milliseconds by the test):
        • The implementation of parallel Streams in JDK 8 still can beat the sequential/for loop when Q is tiny(Here is 0.00002 milliseconds by the test). That's amazing, considering the extra cost brought by parallel computation. It's well done.
        • The implementation of parallel Streams in Abacus is pretty simple and straight forward. The extra cost(starting threads/synchronization/queue...) brought by parallel Streams in Abacus is too bigger to tiny Q(Here is less than 0.001 milliseconds by the test). But it starts to be faster than sequential Streams when Q is big enough(Here is 0.001 milliseconds by the test) and starts to catch the parallel Streams in JDK when Q is bigger(Here is 0.01 milliseconds by the test).
        • Consider using the parallel Streams in Abacus when Q is big enough, specially when IO involved in F. Because one IO operation(e.g. DB/web service request..., Reading/Writing file...) usually takes 1 to 1000 milliseconds, or even longer. By the parallel Streams APIs in Abacus, it's very simple to specify max thread numbers. Sometimes, it's much faster to execute IO/Network requests with a bit more threads. It's fair to say that the parallel Streams in Abacus is high efficient, may same as or faster than the parallel Streams in JDK when Q is big enough, except F is heavy cpu-used operation. Most of the times, the Q is big enough to consider using parallel Stream is because IO/Network is involved in F.
      • JDK 7 is supported by the Streams in Abacus. It's perfect to work with retrolambda on Android
      • All primitive types are supported by Stream APIs in Abacus except boolean


      A bit more about Lambdas/Stream APIs, you may heard that Lambdas/Stream APIs is 5 time slower than imperative programming. It's true when Q and F is VERY, VERY tiny, like f = (int a, int b) -> a + b;. But if we look into the samples in the article and think about it: it just takes less than 1 milliseconds to get the max value in 100k numbers. There is potential performance issue only if the "get the max value in 100K numbers" call many, many times in your API or single request. Otherwise, the difference between 0.1 milliseconds to 0.5 milliseconds can be totally ignored. Usually we meet performance issue only if Q and F is big enough. However, the performance of Lambdas/Streams APIs is closed to for loop when Q and F is big enough. No matter in which scenario, We don't need and should not concern the performance of Lambdas/Stream APIs.

      Although it's is parallel Streams, it doesn't means all the methods are executed in parallel. Because the sequential way is as fast, or even faster than the parallel way for some methods, or is pretty difficult, if not possible, to implement the method by parallel approach. Here are the methods which are executed sequentially even in parallel Streams.

      splitXXX/splitAt/splitBy/slidingXXX/collapse, distinct, reverse, rotate, shuffle, indexed, cached, top, kthLargest, count, toArray, toList, toList, toSet, toMultiset, toLongMultiset, intersection(Collection c), difference(Collection c), symmetricDifference(Collection c), forEach(identity, accumulator, predicate), findFirstOrLast, findFirstAndLast
      Specified by:
      parallel in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      maxThreadNum -
      splitor -
      Returns:
      See Also:
      • #maxThreadNumPerOperation()
    • parallel

      public CharStream parallel(int maxThreadNum, Executor executor)
      Description copied from interface: BaseStream
      // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream. stream.sps(SP.create(maxThreadNum, executor), s -> s.map(f)).filter(p)...; // Or switch the stream back sequential stream if don't use "sps". stream.parallel(maxThreadNum, executor).map(f).sequential().filter(p)...;
      Specified by:
      parallel in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      maxThreadNum -
      executor -
      Returns:
      See Also:
    • parallel

      public CharStream parallel(Executor executor)
      Description copied from interface: BaseStream
       stream.parallel(executor).map(f).filter(p)...;
      
       // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream.
       stream.sps(SP.create(executor), s -> s.map(f)).filter(p)...;
       // Or switch the stream back sequential stream if don't use "sps".
       stream.parallel(executor).map(f).sequential().filter(p)...;
      
       
      Specified by:
      parallel in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      executor -
      Returns:
      See Also:
    • parallel

      public CharStream parallel(int maxThreadNum, BaseStream.Splitor splitor, Executor executor)
      Description copied from interface: BaseStream
       stream.parallel(maxThreadNum, splitor, executor).map(f).filter(p)...;
      
       // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream.
       stream.sps(SP.create(maxThreadNum, splitor, executor), s -> s.map(f)).filter(p)...;
       // Or switch the stream back sequential stream if don't use "sps".
       stream.parallel(maxThreadNum, splitor, executor).map(f).sequential().filter(p)...;
      
       
      Specified by:
      parallel in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      maxThreadNum -
      splitor -
      executor -
      Returns:
      See Also:
    • parallel

      Description copied from interface: BaseStream
       stream.parallel(parallelSettings).map(f).filter(p)...;
      
       // Replace above line of code with "sps" if only "f" need to be parallelized. And "p" is fast enough to be executed in sequential Stream.
       stream.sps(SP.create(parallelSettings), s -> s.map(f)).filter(p)...;
       // Or switch the stream back sequential stream if don't use "sps".
       stream.parallel(parallelSettings).map(f).sequential().filter(p)...;
      
       
      Specified by:
      parallel in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Parameters:
      ps -
      Returns:
      See Also:
    • sps

      public <SS extends BaseStream> SS sps(Function<? super CharStream,? extends SS> ops)
      Description copied from interface: BaseStream
      Temporarily switch the stream to parallel stream for operation ops and then switch back to sequence stream.
      stream().parallel().ops(map/filter/...).sequence()
      Specified by:
      sps in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Type Parameters:
      SS -
      Parameters:
      ops -
      Returns:
    • sps

      public <SS extends BaseStream> SS sps(int maxThreadNum, Function<? super CharStream,? extends SS> ops)
      Description copied from interface: BaseStream
      Temporarily switch the stream to parallel stream for operation ops and then switch back to sequence stream.
      stream().parallel(maxThreadNum).ops(map/filter/...).sequence()
      Specified by:
      sps in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Type Parameters:
      SS -
      Parameters:
      maxThreadNum -
      ops -
      Returns:
    • psp

      public <SS extends BaseStream> SS psp(Function<? super CharStream,? extends SS> ops)
      Description copied from interface: BaseStream
      Temporarily switch the stream to sequence stream for operation ops and then switch back to parallel stream with same maxThreadNum/splitor/asyncExecutor.
      stream().sequence().ops(map/filter/...).parallel(sameMaxThreadNum, sameSplitor, sameAsyncExecutor)
      Specified by:
      psp in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Type Parameters:
      SS -
      Parameters:
      ops -
      Returns:
    • toArray

      public char[] toArray()
      Specified by:
      toArray in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Returns:
    • close

      public void close()
      Description copied from interface: BaseStream
      It will be called by terminal operations in final.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface BaseStream<T,A,P,C,PL,OT,IT,ITER extends Iterator<T>,S extends com.landawn.abacus.util.stream.StreamBase<T,A,P,C,PL,OT,IT,ITER,S>>
      Specified by:
      close in interface Closeable