Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →BiConsumer<T, U> is Java’s functional interface for an operation that accepts two inputs and returns no result. Use it when code receives a pair—such as a map key and value—and needs to perform an action rather than calculate a value to return. Its functional method is accept(T t, U u). Oracle documents the interface in the Java SE 24 API.
What BiConsumer represents
BiConsumer<T, U> is the two-input counterpart to Consumer<T>. The type parameters describe the first and second argument; the method returns void. In other words, it performs an operation—typically one with a side effect—rather than producing a value for its caller.
As an Amazon Associate I earn from qualifying purchases.
BiConsumer<String, Integer> showPair =
(name, count) -> System.out.println(name + ": " + count);
showPair.accept("apples", 3);
A lambda works when the surrounding API expects a BiConsumer. You can also implement the interface in a class or pass a compatible method reference. The interface has been part of Java since Java 8, according to its API documentation.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Use BiConsumer with Map.forEach
Map.forEach is a direct JDK example: it passes each map entry’s key and value to the supplied action. The API accepts a BiConsumer parameterized with the map’s key and value types.
import java.util.Map;
import java.util.function.BiConsumer;
BiConsumer<String, Integer> printEntry =
(key, value) -> System.out.println(key + "=" + value);
Map.of("apples", 3, "pears", 5).forEach(printEntry);
For a map with a specified type, the same pattern can be written inline:
Map<String, Integer> counts = Map.of("apples", 3, "pears", 5);
counts.forEach((key, value) -> System.out.println(key + "=" + value));
Map.forEach processes entries until they have all been processed or the action throws an exception. Do not assume a universal iteration order: some map implementations define an order, while others, including HashMap, do not. See Oracle’s Java SE 24 Map API.
Rank #2
Chain actions with andThen
andThen creates a composed action: the original BiConsumer runs first, followed by the action passed to andThen.
Outdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchWindows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallBiConsumer<String, Integer> logEntry =
(key, value) -> System.out.println("entry: " + key + "=" + value);
BiConsumer<String, Integer> auditEntry =
(key, value) -> audit(key, value);
Map<String, Integer> counts = Map.of("apples", 3, "pears", 5);
counts.forEach(logEntry.andThen(auditEntry));
If the first action throws, the second is skipped. If either action throws, the exception is relayed to the caller. Passing null as the action to andThen throws NullPointerException. These behaviors are specified in Oracle’s BiConsumer API documentation.
Choose the interface by its inputs and result
| Interface | Inputs | Result | Use it when |
|---|---|---|---|
Consumer<T> |
One | None (void) |
An action operates on one item. |
BiConsumer<T, U> |
Two | None (void) |
An action operates on a pair. |
BiFunction<T, U, R> |
Two | A result of type R |
A calculation needs to produce a value from a pair. |
The Map API makes the distinction concrete: forEach uses a BiConsumer to act on each key-value pair, while replaceAll uses a BiFunction because it needs a result to use as the replacement value. Choose based on what the calling API needs: an effect or a returned answer.
Quick Recap
Best Value
Rank #4
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




