I have a double[] and I want to filter out (create a new array without) negative values in one line without adding for loops. Is this possible usin
even simpler, adding up to String[],
use built-in filter filter(StringUtils::isNotEmpty) of org.apache.commons.lang3
import org.apache.commons.lang3.StringUtils;
String test = "a\nb\n\nc\n";
String[] lines = test.split("\\n", -1);
String[] result = Arrays.stream(lines).filter(StringUtils::isNotEmpty).toArray(String[]::new);
System.out.println(Arrays.toString(lines));
System.out.println(Arrays.toString(result));
and output:
[a, b, , c, ]
[a, b, c]