Can I use forEach()
or stream()
on varArgs ?
protected void getSomeIds (List<String>... varArgs) {
for(List lst:varArgs) {
System.out.println("This works");
}
//Following does not compile
varArgs.forEach();
// nor
varArgs.stream();
}
Varargs behave similarly to arrays, so you can get a Stream
of the varargs using Stream.of
:
Stream<List<String>> stream = Stream.of (varArgs);
And you can iterate over them with :
Stream.of(varArgs).forEach (...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With