Mostly it's designed for one-step operation to complete the operation in one step.
<code>java.util.stream.Stream</code> is preferred for multiple phases operation.

@param a
@param fromIndex
@param toIndex
@param filter
@param max
@param supplier
@return
331423
public static <T, R extends Collection<T>, E extends Exception> R filter(final T[] a, final int fromIndex, final int toIndex,
            final Try.Predicate<? super T, E> filter, final int max, final IntFunction<R> supplier) throws E {
        checkFromToIndex(fromIndex, toIndex, len(a));
        N.checkArgNotNull(filter);

        if (N.isNullOrEmpty(a)) {
            return supplier.apply(0);
        }

        final R result = supplier.apply(N.min(9, max, (toIndex - fromIndex)));

        for (int i = fromIndex, cnt = 0; i < toIndex && cnt < max; i++) {
            if (filter.test(a[i])) {
                result.add(a[i]);
                cnt++;
            }
        }

        return result;
    }
231086
public static <T> Filter<T> from(final Sink<T> sink) {
        return new NonMutatingFilter<T>() {
            @Override
            public boolean accepts(T item) throws IOException {
                sink.put(item);
                return true;
            }
            @Override
            public void close() {
                sink.close();
            }
        };
    }
656288
public static boolean[] deleteRange(final boolean[] a, final int fromIndex, final int toIndex) {
        N.checkFromToIndex(fromIndex, toIndex, a.length);

        if (fromIndex == toIndex) {
            return a.clone();
        }

        final boolean[] b = new boolean[a.length - (toIndex - fromIndex)];

        if (fromIndex > 0) {
            N.copy(a, 0, b, 0, fromIndex);
        }

        if (toIndex < a.length) {
            N.copy(a, toIndex, b, fromIndex, a.length - toIndex);
        }

        return b;
    }
1106597
<T, U> Stage<U> doStreamCollectEmpty(
      final Consumer<? super T> consumer, final Supplier<? extends U> supplier
  ) {
    try {
      return this.completed(supplier.get());
    } catch (Exception e) {
      return failed(e);
    }
  }
1309965
@Override
    public CompletableFuture<AttributeIndex> forSegment(long streamSegmentId, Duration timeout) {
        Exceptions.checkNotClosed(this.closed.get(), this);
        SegmentMetadata sm = this.containerMetadata.getStreamSegmentMetadata(streamSegmentId);
        if (sm.isDeleted()) {
            return Futures.failedFuture(new StreamSegmentNotExistsException(sm.getName()));
        }

        // Figure out if we already have this AttributeIndex cached. If not, we need to initialize it.
        CompletableFuture<AttributeIndex> result;
        AtomicReference<SegmentAttributeBTreeIndex> toInitialize = new AtomicReference<>();
        synchronized (this.attributeIndices) {
            result = this.attributeIndices.computeIfAbsent(streamSegmentId, id -> {
                toInitialize.set(new SegmentAttributeBTreeIndex(sm, this.storage, this.cache, this.config, this.executor));
                return new CompletableFuture<>();
            });
        }

        if (toInitialize.get() == null) {
            // We already have it cached - return its future (which should be already completed or will complete once
            // its initialization is done).
            return result;
        } else {
            try {
                // Need to initialize the AttributeIndex and complete the future that we just registered.
                // If this fails, we must fail the Future that we previously registered and unregister any pointers to
                // this index.
                toInitialize.get().initialize(timeout)
                            .thenRun(() -> this.cacheManager.register(toInitialize.get()))
                            .whenComplete((r, ex) -> {
                                if (ex == null) {
                                    result.complete(toInitialize.get());
                                } else {
                                    indexInitializationFailed(streamSegmentId, result, ex);
                                }
                            });
            } catch (Throwable ex) {
                if (!Exceptions.mustRethrow(ex)) {
                    indexInitializationFailed(streamSegmentId, result, ex);
                }
                throw ex;
            }
        }

        return result;
    }
1090302
public static <T> ObjIteratorEx<T> oF(final Supplier<T[]> arraySupplier) {
        N.checkArgNotNull(arraySupplier, "arraySupplier");

        return new ObjIteratorEx<T>() {
            private ObjIteratorEx<T> iterEx = null;
            private boolean isInitialized = false;

            @Override
            public boolean hasNext() {
                if (isInitialized == false) {
                    init();
                }

                return iterEx.hasNext();
            }

            @Override
            public T next() {
                if (isInitialized == false) {
                    init();
                }

                return iterEx.next();
            }

            @Override
            public void skip(long n) {
                N.checkArgNotNegative(n, "n");

                if (isInitialized == false) {
                    init();
                }

                iterEx.skip(n);
            }

            @Override
            public long count() {
                if (isInitialized == false) {
                    init();
                }

                return iterEx.count();
            }

            private void init() {
                if (isInitialized == false) {
                    isInitialized = true;
                    iterEx = ObjIteratorEx.of(arraySupplier.get());
                }
            }
        };
    }
303737
public static FloatStream of(final Supplier<FloatList> supplier) {
        final FloatIterator iter = new FloatIteratorEx() {
            private FloatIterator iterator = null;

            @Override
            public boolean hasNext() {
                if (iterator == null) {
                    init();
                }

                return iterator.hasNext();
            }

            @Override
            public float nextFloat() {
                if (iterator == null) {
                    init();
                }

                return iterator.nextFloat();
            }

            private void init() {
                final FloatList c = supplier.get();

                if (N.isNullOrEmpty(c)) {
                    iterator = FloatIterator.empty();
                } else {
                    iterator = c.iterator();
                }
            }
        };

        return of(iter);
    }
122985
@Override
  public <R> StreamBuilderImpl<R,U>
  collect(SupplierSync<R> init,
          BiConsumerSync<R,T> accum,
          BiConsumerSync<R,R> combiner)
  {
    return new CollectSync<>(this, init, accum, combiner);
  }
749517
public static <T, R, E extends Exception> List<R> map(final T[] a, final int fromIndex, final int toIndex,
            final Try.Function<? super T, ? extends R, E> func) throws E {
        checkFromToIndex(fromIndex, toIndex, len(a));
        N.checkArgNotNull(func);

        if (N.isNullOrEmpty(a)) {
            return new ArrayList<>();
        }

        final List<R> result = new ArrayList<>(toIndex - fromIndex);

        for (int i = fromIndex; i < toIndex; i++) {
            result.add(func.apply(a[i]));
        }

        return result;
    }
713061
public List<XEvent> subList(int fromIndex, int toIndex) {
		XTraceBufferedImpl sublist = (XTraceBufferedImpl) this.clone();
		this.clear();
		for (int i = fromIndex; i < toIndex; i++) {
			try {
				sublist.add(events.get(i));
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return sublist;
	}
699222
public static <T, E extends Exception> IntList mapToInt(final T[] a, final int fromIndex, final int toIndex, final Try.ToIntFunction<? super T, E> func)
            throws E {
        checkFromToIndex(fromIndex, toIndex, len(a));
        N.checkArgNotNull(func);

        if (N.isNullOrEmpty(a)) {
            return new IntList();
        }

        final IntList result = new IntList(toIndex - fromIndex);

        for (int i = fromIndex; i < toIndex; i++) {
            result.add(func.applyAsInt(a[i]));
        }

        return result;
    }
679878
public static Collection<Object> filterByJavaBeanPageProperty(ArrayList<Object> aList,
	String aPropertyName, int fromIndex, int toIndex)
	{

		logger.debug("In Organizer filtering: " + aPropertyName);
		try
		{
			if (aList == null)
				throw new IllegalArgumentException(
				"aCollection required in filterByJavaBeanProperty");

			ArrayList<Object> filteredList = new ArrayList<Object>(aList.size());

			Object bean = null;
			Object beanPropertyValue = null;
			for (Iterator<Object> i = aList.iterator(); i.hasNext();)
			{
				try
				{
					bean = i.next();
					beanPropertyValue = JavaBean.getProperty(bean,
					aPropertyName);
					int beanPropIntVal = Integer.parseInt(
					beanPropertyValue.toString());
					// logger.debug("Got propertyValue: " + beanPropertyValue +
					// " for propertyName: " + beanPropIntVal);
					if (
						(fromIndex <= beanPropIntVal)
						&& (beanPropIntVal <= toIndex))
						{
						filteredList.add(bean);
						// logger.debug("Organizer added bean");
					}
				}
				catch (Exception e)
				{
					logger.debug("error occured : " + e);
				}
			}
			filteredList.trimToSize();
			return filteredList;
		}
		catch (Exception e)
		{
			throw new SystemException(e);
		}
	}
521965
public static IntIterator of(final Supplier<? extends IntIterator> iteratorSupplier) {
        N.checkArgNotNull(iteratorSupplier, "iteratorSupplier");

        return new IntIterator() {
            private IntIterator iter = null;
            private boolean isInitialized = false;

            @Override
            public boolean hasNext() {
                if (isInitialized == false) {
                    init();
                }

                return iter.hasNext();
            }

            @Override
            public int nextInt() {
                if (isInitialized == false) {
                    init();
                }

                return iter.nextInt();
            }

            private void init() {
                if (isInitialized == false) {
                    isInitialized = true;
                    iter = iteratorSupplier.get();
                }
            }
        };
    }
403535
public static <T> ObjIterator<T> of(final Supplier<? extends Iterator<? extends T>> iteratorSupplier) {
        N.checkArgNotNull(iteratorSupplier, "iteratorSupplier");

        return new ObjIterator<T>() {
            private Iterator<? extends T> iter = null;
            private boolean isInitialized = false;

            @Override
            public boolean hasNext() {
                if (isInitialized == false) {
                    init();
                }

                return iter.hasNext();
            }

            @Override
            public T next() {
                if (isInitialized == false) {
                    init();
                }

                return iter.next();
            }

            private void init() {
                if (isInitialized == false) {
                    isInitialized = true;
                    iter = iteratorSupplier.get();
                }
            }
        };
    }
614628
public static <T> List<T> distinct(final Collection<? extends T> c, final int fromIndex, final int toIndex) {
        checkFromToIndex(fromIndex, toIndex, size(c));

        if (N.isNullOrEmpty(c) && fromIndex == 0 && toIndex == 0) {
            return new ArrayList<>();
        }

        final List<T> result = new ArrayList<>();
        final Set<Object> set = new HashSet<>();
        T e = null;

        if (c instanceof List && c instanceof RandomAccess) {
            final List<T> list = (List<T>) c;

            for (int i = fromIndex; i < toIndex; i++) {
                e = list.get(i);

                if (set.add(hashKey(e))) {
                    result.add(e);
                }
            }
        } else {
            final Iterator<? extends T> it = c.iterator();

            for (int i = 0; i < toIndex && it.hasNext(); i++) {
                e = it.next();

                if (i < fromIndex) {
                    continue;
                }

                if (set.add(hashKey(e))) {
                    result.add(e);
                }
            }
        }

        return result;
    }
949757
public static <T> void fill(final List<? super T> list, final int fromIndex, final int toIndex, final T val) {
        checkFromToIndex(fromIndex, toIndex, Integer.MAX_VALUE);

        int size = list.size();

        if (size < toIndex) {
            if (fromIndex < size) {
                for (int i = fromIndex; i < size; i++) {
                    list.set(i, val);
                }
            } else {
                for (int i = size; i < fromIndex; i++) {
                    list.add(null);
                }
            }

            for (int i = 0, len = toIndex - list.size(); i < len; i++) {
                list.add(val);
            }
        } else {
            if (toIndex - fromIndex < FILL_THRESHOLD || list instanceof RandomAccess) {
                for (int i = fromIndex; i < toIndex; i++) {
                    list.set(i, val);
                }
            } else {
                final ListIterator<? super T> itr = list.listIterator(fromIndex);

                for (int i = fromIndex; i < toIndex; i++) {
                    itr.next();

                    itr.set(val);
                }
            }
        }
    }
687382
public static DoubleStream of(final Supplier<DoubleList> supplier) {
        final DoubleIterator iter = new DoubleIteratorEx() {
            private DoubleIterator iterator = null;

            @Override
            public boolean hasNext() {
                if (iterator == null) {
                    init();
                }

                return iterator.hasNext();
            }

            @Override
            public double nextDouble() {
                if (iterator == null) {
                    init();
                }

                return iterator.nextDouble();
            }

            private void init() {
                final DoubleList c = supplier.get();

                if (N.isNullOrEmpty(c)) {
                    iterator = DoubleIterator.empty();
                } else {
                    iterator = c.iterator();
                }
            }
        };

        return of(iter);
    }