I want to filter the CC addresses of the array and want to collect it to the same array,
FOR EXAMPLE
String[] ccAddress = emails.split(";");
ccAddress = Arrays.stream(ccAddress)
.filter(adr -> "".equals(adr) == false)
.collect(Collectors.toArray);// ?????
My question is, 'Is there any direct way to collect filtered elements to the array in Java8' ?
NOTE : I know I can simply collect them to List and write list.toArray() to get array but that is not my question.
Did you checked documentation?
You can use Stream.toArray method:
String[] ccAddress = emails.split(";");
ccAddress = Arrays.stream(ccAddress)
.filter(addr -> !addr.isEmpty())
.toArray(String[]::new);
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