# Uses of Interface
java.util.function.Consumer

Packages that use Consumer
Package
Description
com.sun.net.httpserver
Provides a simple high-level Http server API, which can be used to build embedded HTTP servers.
java.lang
Provides classes that are fundamental to the design of the Java programming language.
java.lang.classfile
Provides classfile parsing, generation, and transformation library.
java.lang.classfile.attribute
Provides interfaces describing `class` file attributes for the `java.lang.classfile` library.
java.lang.foreign
Provides low-level access to memory and functions outside the Java runtime.
java.net.http
HTTP Client and WebSocket APIs
java.nio.channels
Defines channels, which represent connections to entities that are capable of performing I/O operations, such as files and sockets; defines selectors, for multiplexed, non-blocking I/O operations.
java.util
Contains the collections framework, some internationalization support classes, a service loader, properties, random number generation, string parsing and scanning classes, base64 encoding and decoding, a bit array, and several miscellaneous utility classes.
java.util.concurrent
Utility classes commonly useful in concurrent programming.
java.util.function
Functional interfaces provide target types for lambda expressions and method references.
java.util.stream
Classes to support functional-style operations on streams of elements, such as map-reduce transformations on collections.
jdk.jfr.consumer
This package contains classes for consuming Flight Recorder data.
jdk.jshell
Provides interfaces for creating tools, such as a Read-Eval-Print Loop (REPL), which interactively evaluate "snippets" of Java programming language code.
jdk.jshell.execution
Provides implementation support for building JShell execution engines.
jdk.management.jfr
This package contains classes to control and monitor Flight Recorder over Java Management Extensions (JMX).

- ## Uses of Consumer in com.sun.net.httpserver

  Methods in com.sun.net.httpserver with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `static Filter`
  Filter.`afterHandler(String description, Consumer<HttpExchange> operation)`
  Returns a post-processing `Filter` with the given description and operation.
  `static Filter`
  Filter.`beforeHandler(String description, Consumer<HttpExchange> operation)`
  Returns a pre-processing `Filter` with the given description and operation.

- ## Uses of Consumer in java.lang

  Methods in java.lang with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `default void`
  Iterable.`forEach(Consumer<? super T> action)`
  Performs the given action for each element of the `Iterable` until all elements have been processed or the action throws an exception.
  `void`
  StackWalker.`forEach(Consumer<? super StackWalker.StackFrame> action)`
  Performs the given action on each element of `StackFrame` stream of the current thread, traversing from the top frame of the stack, which is the method calling this `forEach` method.

- ## Uses of Consumer in java.lang.classfile

  Subinterfaces of Consumer in java.lang.classfile
  Modifier and Type
  Interface
  Description
  `interface`
  `ClassBuilder`
  A builder for a `class` file.
  `interface`
  `ClassFileBuilder<E extends ClassFileElement, B extends ClassFileBuilder<E,B>>`
  A builder for a `CompoundElement`, which accepts the member elements to be integrated into the built structure.
  `interface`
  `CodeBuilder`
  A builder for `Code` attributes (method bodies).
  `static interface`
  `CodeBuilder.BlockCodeBuilder`
  A builder for blocks of code.
  `interface`
  `FieldBuilder`
  A builder for fields.
  `interface`
  `MethodBuilder`
  A builder for methods.
  Methods in java.lang.classfile with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `default CodeBuilder`
  CodeBuilder.`block(Consumer<CodeBuilder.BlockCodeBuilder> handler)`
  Adds a lexical block to the method being built.
  `byte[]`
  ClassFile.`build(ClassEntry thisClassEntry, ConstantPoolBuilder constantPool, Consumer<? super ClassBuilder> handler)`
  Builds a `class` file into a byte array using the provided constant pool builder.
  `default byte[]`
  ClassFile.`build(ClassDesc thisClass, Consumer<? super ClassBuilder> handler)`
  Builds a `class` file into a byte array.
  `default byte[]`
  ClassFile.`buildModule(ModuleAttribute moduleAttribute, Consumer<? super ClassBuilder> handler)`
  Builds a module descriptor into a byte array.
  `default void`
  ClassFile.`buildModuleTo(Path path, ModuleAttribute moduleAttribute, Consumer<? super ClassBuilder> handler)`
  Builds a module descriptor into a file in a file system.
  `default void`
  ClassFile.`buildTo(Path path, ClassEntry thisClassEntry, ConstantPoolBuilder constantPool, Consumer<? super ClassBuilder> handler)`
  Builds a `class` file into a file in a file system using the provided constant pool builder.
  `default void`
  ClassFile.`buildTo(Path path, ClassDesc thisClass, Consumer<ClassBuilder> handler)`
  Builds a `class` file into a file in a file system.
  `CodeBuilder.CatchBuilder`
  CodeBuilder.CatchBuilder.`catching(ClassDesc exceptionType, Consumer<CodeBuilder.BlockCodeBuilder> catchHandler)`
  Adds a catch block that catches an exception of the given type.
  `void`
  CodeBuilder.CatchBuilder.`catchingAll(Consumer<CodeBuilder.BlockCodeBuilder> catchAllHandler)`
  Adds a "catch" block that catches all exceptions.
  `CodeBuilder.CatchBuilder`
  CodeBuilder.CatchBuilder.`catchingMulti(List<ClassDesc> exceptionTypes, Consumer<CodeBuilder.BlockCodeBuilder> catchHandler)`
  Adds a catch block that catches exceptions of the given types.
  `static ClassTransform`
  ClassTransform.`endHandler(Consumer<ClassBuilder> finisher)`
  Creates a class transform that passes each element through to the builder, and calls the specified function when transformation is complete.
  `static CodeTransform`
  CodeTransform.`endHandler(Consumer<CodeBuilder> finisher)`
  Creates a code transform that passes each element through to the builder, and calls the specified function when transformation is complete.
  `static FieldTransform`
  FieldTransform.`endHandler(Consumer<FieldBuilder> finisher)`
  Creates a field transform that passes each element through to the builder, and calls the specified function when transformation is complete.
  `static MethodTransform`
  MethodTransform.`endHandler(Consumer<MethodBuilder> finisher)`
  Creates a method transform that passes each element through to the builder, and calls the specified function when transformation is complete.
  `void`
  CompoundElement.`forEach(Consumer<? super E> consumer)`
  Invokes the provided handler with each member element in this compound element.
  `default CodeBuilder`
  CodeBuilder.`ifThen(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler)`
  Adds an "if-then" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.
  `default CodeBuilder`
  CodeBuilder.`ifThen(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler)`
  Adds an "if-then" block that is conditional on the `boolean` value on top of the operand stack.
  `default CodeBuilder`
  CodeBuilder.`ifThenElse(Opcode opcode, Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler)`
  Adds an "if-then-else" block that is conditional on the value(s) on top of the operand stack in accordance with the given opcode.
  `default CodeBuilder`
  CodeBuilder.`ifThenElse(Consumer<CodeBuilder.BlockCodeBuilder> thenHandler, Consumer<CodeBuilder.BlockCodeBuilder> elseHandler)`
  Adds an "if-then-else" block that is conditional on the `boolean` value on top of the operand stack.
  `default CodeBuilder`
  CodeBuilder.`transforming(CodeTransform transform, Consumer<CodeBuilder> handler)`
  Apply a transform to the code built by a handler, directing results to this builder.
  `default CodeBuilder`
  CodeBuilder.`trying(Consumer<CodeBuilder.BlockCodeBuilder> tryHandler, Consumer<CodeBuilder.CatchBuilder> catchesHandler)`
  Adds a "try-catch" block comprising one try block and zero or more catch blocks.
  `MethodBuilder`
  MethodBuilder.`withCode(Consumer<? super CodeBuilder> code)`
  Build the method body for this method.
  `ClassBuilder`
  ClassBuilder.`withField(Utf8Entry name, Utf8Entry descriptor, Consumer<? super FieldBuilder> handler)`
  Adds a field.
  `default ClassBuilder`
  ClassBuilder.`withField(String name, ClassDesc descriptor, Consumer<? super FieldBuilder> handler)`
  Adds a field.
  `ClassBuilder`
  ClassBuilder.`withMethod(Utf8Entry name, Utf8Entry descriptor, int methodFlags, Consumer<? super MethodBuilder> handler)`
  Adds a method.
  `default ClassBuilder`
  ClassBuilder.`withMethod(String name, MethodTypeDesc descriptor, int methodFlags, Consumer<? super MethodBuilder> handler)`
  Adds a method.
  `default ClassBuilder`
  ClassBuilder.`withMethodBody(Utf8Entry name, Utf8Entry descriptor, int methodFlags, Consumer<? super CodeBuilder> handler)`
  Adds a method, with only access flags and a `CodeModel`.
  `default ClassBuilder`
  ClassBuilder.`withMethodBody(String name, MethodTypeDesc descriptor, int methodFlags, Consumer<? super CodeBuilder> handler)`
  Adds a method, with only access flags and a `CodeModel`.

- ## Uses of Consumer in java.lang.classfile.attribute

  Methods in java.lang.classfile.attribute with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `static ModuleAttribute`
  ModuleAttribute.`of(ModuleEntry moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilder> attrHandler)`
  Returns a `Module` attribute.
  `static ModuleAttribute`
  ModuleAttribute.`of(ModuleDesc moduleName, Consumer<ModuleAttribute.ModuleAttributeBuilder> attrHandler)`
  Returns a `Module` attribute.

- ## Uses of Consumer in java.lang.foreign

  Methods in java.lang.foreign with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `MemorySegment`
  MemorySegment.`reinterpret(long newSize, Arena arena, Consumer<MemorySegment> cleanup)`
  Restricted.
  Returns a new segment with the same address as this segment, but with the provided size and the provided arena's scope.
  `MemorySegment`
  MemorySegment.`reinterpret(Arena arena, Consumer<MemorySegment> cleanup)`
  Restricted.
  Returns a new memory segment with the same address and size as this segment, but with the provided arena's scope.

- ## Uses of Consumer in java.net.http

  Methods in java.net.http with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `static HttpResponse.BodyHandler<Void>`
  HttpResponse.BodyHandlers.`ofByteArrayConsumer(Consumer<Optional<byte[]>> consumer)`
  Returns a `BodyHandler<Void>` that returns a `BodySubscriber``<Void>` obtained from `BodySubscribers.ofByteArrayConsumer(Consumer)`.
  `static HttpResponse.BodySubscriber<Void>`
  HttpResponse.BodySubscribers.`ofByteArrayConsumer(Consumer<Optional<byte[]>> consumer)`
  Returns a `BodySubscriber` which provides the incoming body data to the provided Consumer of `Optional<byte[]>`.

- ## Uses of Consumer in java.nio.channels

  Methods in java.nio.channels with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `int`
  Selector.`select(Consumer<SelectionKey> action)`
  Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.
  `int`
  Selector.`select(Consumer<SelectionKey> action, long timeout)`
  Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.
  `int`
  Selector.`selectNow(Consumer<SelectionKey> action)`
  Selects and performs an action on the keys whose corresponding channels are ready for I/O operations.

- ## Uses of Consumer in java.util

  Methods in java.util with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `void`
  ArrayDeque.`forEach(Consumer<? super E> action)`
  `void`
  ArrayList.`forEach(Consumer<? super E> action)`
  `void`
  PriorityQueue.`forEach(Consumer<? super E> action)`
  `void`
  Vector.`forEach(Consumer<? super E> action)`
  `default void`
  Iterator.`forEachRemaining(Consumer<? super E> action)`
  Performs the given action for each remaining element until all elements have been processed or the action throws an exception.
  `default void`
  PrimitiveIterator.OfDouble.`forEachRemaining(Consumer<? super Double> action)`
  Performs the given action for each remaining element until all elements have been processed or the action throws an exception.
  `default void`
  PrimitiveIterator.OfInt.`forEachRemaining(Consumer<? super Integer> action)`
  Performs the given action for each remaining element until all elements have been processed or the action throws an exception.
  `default void`
  PrimitiveIterator.OfLong.`forEachRemaining(Consumer<? super Long> action)`
  Performs the given action for each remaining element until all elements have been processed or the action throws an exception.
  `default void`
  Spliterator.`forEachRemaining(Consumer<? super T> action)`
  Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.
  `default void`
  Spliterator.OfDouble.`forEachRemaining(Consumer<? super Double> action)`
  Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.
  `default void`
  Spliterator.OfInt.`forEachRemaining(Consumer<? super Integer> action)`
  Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.
  `default void`
  Spliterator.OfLong.`forEachRemaining(Consumer<? super Long> action)`
  Performs the given action for each remaining element, sequentially in the current thread, until all elements have been processed or the action throws an exception.
  `void`
  Optional.`ifPresent(Consumer<? super T> action)`
  If a value is present, performs the given action with the value, otherwise does nothing.
  `void`
  Optional.`ifPresentOrElse(Consumer<? super T> action, Runnable emptyAction)`
  If a value is present, performs the given action with the value, otherwise performs the given empty-based action.
  `default boolean`
  Spliterator.OfDouble.`tryAdvance(Consumer<? super Double> action)`
  If a remaining element exists: performs the given action on it, returning `true`; else returns `false`.
  `default boolean`
  Spliterator.OfInt.`tryAdvance(Consumer<? super Integer> action)`
  If a remaining element exists: performs the given action on it, returning `true`; else returns `false`.
  `default boolean`
  Spliterator.OfLong.`tryAdvance(Consumer<? super Long> action)`
  If a remaining element exists: performs the given action on it, returning `true`; else returns `false`.
  `boolean`
  Spliterator.`tryAdvance(Consumer<? super T> action)`
  If a remaining element exists: performs the given action on it, returning `true`; else returns `false`.

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

  Methods in java.util.concurrent with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `CompletableFuture<Void>`
  CompletableFuture.`acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action)`
  `CompletionStage<Void>`
  CompletionStage.`acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action)`
  Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed with the corresponding result as argument to the supplied action.
  `CompletableFuture<Void>`
  CompletableFuture.`acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action)`
  `CompletableFuture<Void>`
  CompletableFuture.`acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor)`
  `CompletionStage<Void>`
  CompletionStage.`acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action)`
  Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using this stage's default asynchronous execution facility, with the corresponding result as argument to the supplied action.
  `CompletionStage<Void>`
  CompletionStage.`acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor)`
  Returns a new CompletionStage that, when either this or the other given stage complete normally, is executed using the supplied executor, with the corresponding result as argument to the supplied action.
  `CompletableFuture<Void>`
  SubmissionPublisher.`consume(Consumer<? super T> consumer)`
  Processes all published items using the given Consumer function.
  `void`
  ArrayBlockingQueue.`forEach(Consumer<? super E> action)`
  `<U> void`
  ConcurrentHashMap.`forEach(long parallelismThreshold, BiFunction<? super K, ? super V, ? extends U> transformer, Consumer<? super U> action)`
  Performs the given action for each non-null transformation of each (key, value).
  `void`
  ConcurrentLinkedDeque.`forEach(Consumer<? super E> action)`
  `void`
  ConcurrentLinkedQueue.`forEach(Consumer<? super E> action)`
  `void`
  CopyOnWriteArrayList.`forEach(Consumer<? super E> action)`
  `void`
  CopyOnWriteArraySet.`forEach(Consumer<? super E> action)`
  `void`
  LinkedBlockingDeque.`forEach(Consumer<? super E> action)`
  `void`
  LinkedBlockingQueue.`forEach(Consumer<? super E> action)`
  `void`
  LinkedTransferQueue.`forEach(Consumer<? super E> action)`
  `void`
  PriorityBlockingQueue.`forEach(Consumer<? super E> action)`
  `void`
  ConcurrentHashMap.`forEachEntry(long parallelismThreshold, Consumer<? super Map.Entry<K,V>> action)`
  Performs the given action for each entry.
  `<U> void`
  ConcurrentHashMap.`forEachEntry(long parallelismThreshold, Function<Map.Entry<K,V>, ? extends U> transformer, Consumer<? super U> action)`
  Performs the given action for each non-null transformation of each entry.
  `void`
  ConcurrentHashMap.`forEachKey(long parallelismThreshold, Consumer<? super K> action)`
  Performs the given action for each key.
  `<U> void`
  ConcurrentHashMap.`forEachKey(long parallelismThreshold, Function<? super K, ? extends U> transformer, Consumer<? super U> action)`
  Performs the given action for each non-null transformation of each key.
  `void`
  ConcurrentHashMap.`forEachValue(long parallelismThreshold, Consumer<? super V> action)`
  Performs the given action for each value.
  `<U> void`
  ConcurrentHashMap.`forEachValue(long parallelismThreshold, Function<? super V, ? extends U> transformer, Consumer<? super U> action)`
  Performs the given action for each non-null transformation of each value.
  `<V> ForkJoinTask<V>`
  ForkJoinPool.`submitWithTimeout(Callable<V> callable, long timeout, TimeUnit unit, Consumer<? super ForkJoinTask<V>> timeoutAction)`
  Submits a task executing the given function, cancelling the task or performing a given timeoutAction if not completed within the given timeout period.
  `CompletableFuture<Void>`
  CompletableFuture.`thenAccept(Consumer<? super T> action)`
  `CompletionStage<Void>`
  CompletionStage.`thenAccept(Consumer<? super T> action)`
  Returns a new CompletionStage that, when this stage completes normally, is executed with this stage's result as the argument to the supplied action.
  `CompletableFuture<Void>`
  CompletableFuture.`thenAcceptAsync(Consumer<? super T> action)`
  `CompletableFuture<Void>`
  CompletableFuture.`thenAcceptAsync(Consumer<? super T> action, Executor executor)`
  `CompletionStage<Void>`
  CompletionStage.`thenAcceptAsync(Consumer<? super T> action)`
  Returns a new CompletionStage that, when this stage completes normally, is executed using this stage's default asynchronous execution facility, with this stage's result as the argument to the supplied action.
  `CompletionStage<Void>`
  CompletionStage.`thenAcceptAsync(Consumer<? super T> action, Executor executor)`
  Returns a new CompletionStage that, when this stage completes normally, is executed using the supplied Executor, with this stage's result as the argument to the supplied action.

- ## Uses of Consumer in java.util.function

  Methods in java.util.function that return Consumer
  Modifier and Type
  Method
  Description
  `default Consumer<T>`
  Consumer.`andThen(Consumer<? super T> after)`
  Returns a composed `Consumer` that performs, in sequence, this operation followed by the `after` operation.
  Methods in java.util.function with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `default Consumer<T>`
  Consumer.`andThen(Consumer<? super T> after)`
  Returns a composed `Consumer` that performs, in sequence, this operation followed by the `after` operation.

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

  Subinterfaces of Consumer in java.util.stream
  Modifier and Type
  Interface
  Description
  `static interface`
  `Stream.Builder<T>`
  A mutable builder for a `Stream`.
  Methods in java.util.stream with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `void`
  Stream.`forEach(Consumer<? super T> action)`
  Performs an action for each element of this stream.
  `void`
  Stream.`forEachOrdered(Consumer<? super T> action)`
  Performs an action for each element of this stream, in the encounter order of the stream if the stream has a defined encounter order.
  `Stream<T>`
  Stream.`peek(Consumer<? super T> action)`
  Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed from the resulting stream.
  Method parameters in java.util.stream with type arguments of type Consumer
  Modifier and Type
  Method
  Description
  `default <R> Stream<R>`
  Stream.`mapMulti(BiConsumer<? super T, ? super Consumer<R>> mapper)`
  Returns a stream consisting of the results of replacing each element of this stream with multiple elements, specifically zero or more elements.

- ## Uses of Consumer in jdk.jfr.consumer

  Methods in jdk.jfr.consumer with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `void`
  EventStream.`onError(Consumer<Throwable> action)`
  Registers an action to perform if an exception occurs.
  `void`
  RecordingStream.`onError(Consumer<Throwable> action)`
  `void`
  EventStream.`onEvent(String eventName, Consumer<RecordedEvent> action)`
  Registers an action to perform on all events matching a name.
  `void`
  EventStream.`onEvent(Consumer<RecordedEvent> action)`
  Registers an action to perform on all events in the stream.
  `void`
  RecordingStream.`onEvent(String eventName, Consumer<RecordedEvent> action)`
  `void`
  RecordingStream.`onEvent(Consumer<RecordedEvent> action)`
  `default void`
  EventStream.`onMetadata(Consumer<MetadataEvent> action)`
  Registers an action to perform when new metadata arrives in the stream.
  `void`
  RecordingStream.`onMetadata(Consumer<MetadataEvent> action)`
  Registers an action to perform when new metadata arrives in the stream.

- ## Uses of Consumer in jdk.jshell

  Methods in jdk.jshell with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `JShell.Subscription`
  JShell.`onShutdown(Consumer<JShell> listener)`
  Register a callback to be called when this JShell instance terminates.
  `JShell.Subscription`
  JShell.`onSnippetEvent(Consumer<SnippetEvent> listener)`
  Register a callback to be called when the Status of a snippet changes.

- ## Uses of Consumer in jdk.jshell.execution

  Methods in jdk.jshell.execution with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `static void`
  Util.`detectJdiExitEvent(VirtualMachine vm, Consumer<String> unbiddenExitHandler)`
  Monitor the JDI event stream for `VMDeathEvent` and `VMDisconnectEvent`.
  Method parameters in jdk.jshell.execution with type arguments of type Consumer
  Modifier and Type
  Method
  Description
  `static void`
  Util.`forwardExecutionControlAndIO(ExecutionControl ec, InputStream inStream, OutputStream outStream, Map<String, Consumer<OutputStream>> outputStreamMap, Map<String, Consumer<InputStream>> inputStreamMap)`
  Forward commands from the input to the specified `ExecutionControl` instance, then responses back on the output.

- ## Uses of Consumer in jdk.management.jfr

  Methods in jdk.management.jfr with parameters of type Consumer
  Modifier and Type
  Method
  Description
  `void`
  RemoteRecordingStream.`onError(Consumer<Throwable> action)`
  `void`
  RemoteRecordingStream.`onEvent(String eventName, Consumer<RecordedEvent> action)`
  `void`
  RemoteRecordingStream.`onEvent(Consumer<RecordedEvent> action)`