Use a Stream and its filter method. I do not unfortunately know how to divide a Stream in two depending on the results of filtering. Won't work in Java7.
The first line uses the
stream() method of the Arrays class to create a sequential
Stream.
The second line turns it into a parallel Stream. There is an overhead to parallelisation, so you should delete that line for small collections. I do not know how large a collection would have to be to benefit from parallel processing, but maybe over 1000 elements.
The 3rd line uses the fact that you can create a Scanner object to scan a String and then use its methods. That will return true if you pass a String like "12345.6789 rammie singh". You can do all sorts of other things. In that expression, you are calling the next String s. The compiler “knows” it is dealing with a Stream<String> and can use it in the predicate to the right of the ->
An alternative would be
...(s ->s.matches(myRegex))...
Depends on what you are going to do.
All elements which match that
predicate are retained in the Stream.
Then you call its
toArray() method which requires something to start it off, so you pass the type
String[]=array of Strings, followed by the double colon operator and the keyword new which means to look for the constructor for that class. Yes, you can use that construct even though you never write
new FooArray().
You do of course often write
new String[123], so what the Stream does is to look for that construct and supply it with the int number, i.e. the size of the Stream, to create such an array.