Using a filter in streams
3 answers
toArraycreates String[], containing the result filter, in your case, all lines whose length is greater than 4. filterreturns a Stream, and therefore you convert it to an array.
To print the filtered result, rather than save it to an array
Arrays.stream(arr).filter(s -> s.length() > 4).forEach(System.out::println);
+3