<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Collections.max(List.of(a, b))?</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Tue, May 13, 2025 at 7:12 PM Tagir Valeev <<a href="mailto:amaembo@gmail.com">amaembo@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>The alternatives we have now:</div><div>BinaryOperator.maxBy(Comparator.<T>naturalOrder()).apply(a, b);</div><div>This speaks clearly about the intent (we'd like to get the maximum and we write 'maxBy') but very wordy.</div><div><br></div><div>Stream.of(a, b).max(Comparator.naturalOrder()).get();</div><div>Also clear and a little bit shorter, but has an unnecessary Optional in-between (we know that we have at least one element, so the result is always present) and we have to mention the comparator. Finally, it might be much less efficient than expected.</div></div>
</blockquote></div></div>