Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert stream to String... (3 dot)

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]

like image 779
dreambigcoder Avatar asked Sep 14 '25 05:09

dreambigcoder


1 Answers

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);
like image 198
Karol Dowbecki Avatar answered Sep 15 '25 20:09

Karol Dowbecki