Do you need concatenate(), Stephan? Let's try without.Thie following might be a more elegant way to deal with a 0‑length input:-I can now see why you used concatenate(): it “forces” the users to pass at least one method argument.
Why does OptionalInt#orElseThrow() take Supplier<X extends Throwable> as a paremeter type rather than Exception or similar?
Yep. This is something I learned from Effective Java. When you want to operate on an arbitrary number of parameters, use regular parameters for the required minimum number of parameters and use varargs for the optional additional parameters. That way the compiler will ensure you get enough parameters, rather than having to rely on runtime exceptions.
Campbell Ritchie wrote:Why does OptionalInt#orElseThrow() take Supplier<X extends Throwable> as a paremeter type rather than Exception or similar?
Because you don't want to go around creating objects until you definitely need them. Building exception stack traces may be quite expensive. For the same reason you should prefer Map.computeIfAbsent() over Map.putIfAbsent(), and the Logger method overloads that take a Supplier rather than a String.