package Java; import java.util.function.BiConsumer; import java.util.Iterator; import java.util.Map; /** @see java.util.Collections */ public final class Collections { private Collections() {} /** Performs the given action for each remaining key-value pair of the iterator until all pairs have * been processed or the action throws an exception. Use this method for iterations that require * access to the iterator; otherwise use `Map.{@linkplain Map#forEach(BiConsumer) forEach}`. * * @param The type of map key. * @param The type of mapped value. * @see Iterator#forEachRemaining(java.util.function.Consumer) */ public static void forEachRemaining​( final Iterator> iterator, final BiConsumer action ) { iterator.forEachRemaining( entry -> action.accept( entry.getKey(), entry.getValue() )); }} // Copyright © 2020-2021 Michael Allan. Licence MIT.