I have a line:
String modulesToUpdate = "potato:module1, tomato:module2";
I want to get only from him:
module1
module2
First I need to break it into "," and then into ":"
So, I did this:
String files[] = modulesToUpdate.split(",");
for(String file: files){
String f[] = file.split(":");
for(int i=0; i<f.length; i++){
System.out.println(f[1])
}
}
This works, but the loop in the loop is not elegant.
I am trying to do the same with threads.
So, I did this:
Stream.of(modulesToUpdate)
.map(line -> line.split(","))
.flatMap(Arrays::stream)
.flatMap(Pattern.compile(":")::splitAsStream)
.forEach(f-> System.out.println(f.toString().trim()));
Output:
potato
module1
tomato
module2
How to reduce / filter it to get only:
module1
module2
nidis source
share