Uses of Interface java.util.function.Supplier (Java Platform SE 8 )
Date: 2026-04-17

## Uses of Interface
java.util.function.Supplier

- Packages that use Supplier
  Package | Description
  --- | ---
  java.lang | Provides classes that are fundamental to the design of the Java programming language.
  java.util | Contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).
  java.util.concurrent | Utility classes commonly useful in concurrent programming.
  java.util.logging | Provides the classes and interfaces of the JavaTM 2 platform's core logging facilities.
  java.util.stream | Classes to support functional-style operations on streams of elements, such as map-reduce transformations on collections.

- - ### Uses of Supplier in java.lang

    Methods in java.lang with parameters of type Supplier
    Modifier and Type | Method and Description
    --- | ---
    `static <S> ThreadLocal<S>` | ThreadLocal.`withInitial(Supplier<? extends S> supplier)` Creates a thread local variable.

  - ### Uses of Supplier in java.util

    Methods in java.util with parameters of type Supplier
    Modifier and Type | Method and Description
    --- | ---
    `T` | Optional.`orElseGet(Supplier<? extends T> other)` Return the value if present, otherwise invoke `other` and return the result of that invocation.
    `<X extends Throwable> T` | Optional.`orElseThrow(Supplier<? extends X> exceptionSupplier)` Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
    `<X extends Throwable> double` | OptionalDouble.`orElseThrow(Supplier<X> exceptionSupplier)` Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
    `<X extends Throwable> int` | OptionalInt.`orElseThrow(Supplier<X> exceptionSupplier)` Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
    `<X extends Throwable> long` | OptionalLong.`orElseThrow(Supplier<X> exceptionSupplier)` Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
    `static <T> T` | Objects.`requireNonNull(T obj, Supplier<String> messageSupplier)` Checks that the specified object reference is not `null` and throws a customized `NullPointerException` if it is.

  - ### Uses of Supplier in java.util.concurrent

    Methods in java.util.concurrent with parameters of type Supplier
    Modifier and Type | Method and Description
    --- | ---
    `static <U> CompletableFuture<U>` | CompletableFuture.`supplyAsync(Supplier<U> supplier)` Returns a new CompletableFuture that is asynchronously completed by a task running in the `ForkJoinPool.commonPool()` with the value obtained by calling the given Supplier.
    `static <U> CompletableFuture<U>` | CompletableFuture.`supplyAsync(Supplier<U> supplier, Executor executor)` Returns a new CompletableFuture that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Supplier.

  - ### Uses of Supplier in java.util.logging

    Methods in java.util.logging with parameters of type Supplier
    Modifier and Type | Method and Description
    --- | ---
    `void` | Logger.`config(Supplier<String> msgSupplier)` Log a CONFIG message, which is only to be constructed if the logging level is such that the message will actually be logged.
    `void` | Logger.`fine(Supplier<String> msgSupplier)` Log a FINE message, which is only to be constructed if the logging level is such that the message will actually be logged.
    `void` | Logger.`finer(Supplier<String> msgSupplier)` Log a FINER message, which is only to be constructed if the logging level is such that the message will actually be logged.
    `void` | Logger.`finest(Supplier<String> msgSupplier)` Log a FINEST message, which is only to be constructed if the logging level is such that the message will actually be logged.
    `void` | Logger.`info(Supplier<String> msgSupplier)` Log a INFO message, which is only to be constructed if the logging level is such that the message will actually be logged.
    `void` | Logger.`log(Level level, Supplier<String> msgSupplier)` Log a message, which is only to be constructed if the logging level is such that the message will actually be logged.
    `void` | Logger.`log(Level level, Throwable thrown, Supplier<String> msgSupplier)` Log a lazily constructed message, with associated Throwable information.
    `void` | Logger.`logp(Level level, String sourceClass, String sourceMethod, Supplier<String> msgSupplier)` Log a lazily constructed message, specifying source class and method, with no arguments.
    `void` | Logger.`logp(Level level, String sourceClass, String sourceMethod, Throwable thrown, Supplier<String> msgSupplier)` Log a lazily constructed message, specifying source class and method, with associated Throwable information.
    `void` | Logger.`severe(Supplier<String> msgSupplier)` Log a SEVERE message, which is only to be constructed if the logging level is such that the message will actually be logged.
    `void` | Logger.`warning(Supplier<String> msgSupplier)` Log a WARNING message, which is only to be constructed if the logging level is such that the message will actually be logged.

  - ### Uses of Supplier in java.util.stream

    Methods in java.util.stream that return Supplier
    Modifier and Type | Method and Description
    --- | ---
    `Supplier<A>` | Collector.`supplier()` A function that creates and returns a new mutable result container.

    Methods in java.util.stream with parameters of type Supplier
    Modifier and Type | Method and Description
    --- | ---
    `<R> R` | Stream.`collect(Supplier<R> supplier, BiConsumer<R,? super T> accumulator, BiConsumer<R,R> combiner)` Performs a mutable reduction operation on the elements of this stream.
    `<R> R` | DoubleStream.`collect(Supplier<R> supplier, ObjDoubleConsumer<R> accumulator, BiConsumer<R,R> combiner)` Performs a mutable reduction operation on the elements of this stream.
    `<R> R` | IntStream.`collect(Supplier<R> supplier, ObjIntConsumer<R> accumulator, BiConsumer<R,R> combiner)` Performs a mutable reduction operation on the elements of this stream.
    `<R> R` | LongStream.`collect(Supplier<R> supplier, ObjLongConsumer<R> accumulator, BiConsumer<R,R> combiner)` Performs a mutable reduction operation on the elements of this stream.
    `static DoubleStream` | StreamSupport.`doubleStream(Supplier<? extends Spliterator.OfDouble> supplier, int characteristics, boolean parallel)` Creates a new sequential or parallel `DoubleStream` from a `Supplier` of `Spliterator.OfDouble`.
    `static <T> Stream<T>` | Stream.`generate(Supplier<T> s)` Returns an infinite sequential unordered stream where each element is generated by the provided `Supplier`.
    `static <T,K,D,A,M extends Map<K,D>> Collector<T,?,M>` | Collectors.`groupingBy(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)` Returns a `Collector` implementing a cascaded "group by" operation on input elements of type `T`, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstream `Collector`.
    `static <T,K,A,D,M extends ConcurrentMap<K,D>> Collector<T,?,M>` | Collectors.`groupingByConcurrent(Function<? super T,? extends K> classifier, Supplier<M> mapFactory, Collector<? super T,A,D> downstream)` Returns a concurrent `Collector` implementing a cascaded "group by" operation on input elements of type `T`, grouping elements according to a classification function, and then performing a reduction operation on the values associated with a given key using the specified downstream `Collector`.
    `static IntStream` | StreamSupport.`intStream(Supplier<? extends Spliterator.OfInt> supplier, int characteristics, boolean parallel)` Creates a new sequential or parallel `IntStream` from a `Supplier` of `Spliterator.OfInt`.
    `static LongStream` | StreamSupport.`longStream(Supplier<? extends Spliterator.OfLong> supplier, int characteristics, boolean parallel)` Creates a new sequential or parallel `LongStream` from a `Supplier` of `Spliterator.OfLong`.
    `static <T,A,R> Collector<T,A,R>` | Collector.`of(Supplier<A> supplier, BiConsumer<A,T> accumulator, BinaryOperator<A> combiner, Function<A,R> finisher, Collector.Characteristics... characteristics)` Returns a new `Collector` described by the given `supplier`, `accumulator`, `combiner`, and `finisher` functions.
    `static <T,R> Collector<T,R,R>` | Collector.`of(Supplier<R> supplier, BiConsumer<R,T> accumulator, BinaryOperator<R> combiner, Collector.Characteristics... characteristics)` Returns a new `Collector` described by the given `supplier`, `accumulator`, and `combiner` functions.
    `static <T> Stream<T>` | StreamSupport.`stream(Supplier<? extends Spliterator<T>> supplier, int characteristics, boolean parallel)` Creates a new sequential or parallel `Stream` from a `Supplier` of `Spliterator`.
    `static <T,C extends Collection<T>> Collector<T,?,C>` | Collectors.`toCollection(Supplier<C> collectionFactory)` Returns a `Collector` that accumulates the input elements into a new `Collection`, in encounter order.
    `static <T,K,U,M extends ConcurrentMap<K,U>> Collector<T,?,M>` | Collectors.`toConcurrentMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapSupplier)` Returns a concurrent `Collector` that accumulates elements into a `ConcurrentMap` whose keys and values are the result of applying the provided mapping functions to the input elements.
    `static <T,K,U,M extends Map<K,U>> Collector<T,?,M>` | Collectors.`toMap(Function<? super T,? extends K> keyMapper, Function<? super T,? extends U> valueMapper, BinaryOperator<U> mergeFunction, Supplier<M> mapSupplier)` Returns a `Collector` that accumulates elements into a `Map` whose keys and values are the result of applying the provided mapping functions to the input elements.

Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.