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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.