How to convert a stream to String...(3 dot)
I have a method mapToSomeObj(String... args)
How do I pass Stream object into mapToSomeObj method.
When I pass Obj.stream().map(a->a.getVal()).toArray()
I get [string1, string2]
The 3 dots stand for Vararg declaration which is compiled to an array, making mapToSomeObj(String...)
method signature the same as mapToSomeObj(String[])
signature.
Assuming a.getVal()
returns a String
your approach should work:
String[] arr = Obj.stream().map(a::getVal).toArray(String[]::new);
mapToSomeObj(arr);
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