java - Regex not working with Stream filter() -
i trying text out line when using new stream
in java 8.
this reading in:
46 [core1] 56 [core1] 45 [core1] 45 [core2] 67 [core2] 54 [core2]
and here code read currently:
path path = paths.get("./src/main/resources/", "data.txt"); try(stream<string> lines = files.lines(path)){ list<integer> temps = new arraylist<>(); lines .filter(line -> line.contains("[core1]")) .filter(line -> line.contains("(\\d+).*")) .flatmaptoint(temperature -> intstream.of(integer.parseint(temperature))) .foreach(system.out::println); system.out.print(temps.size()); }
i have checked regex expression in https://www.regex101.com/ , seems work fine. if search [core1]
string, find it.
the problem when using of together, 0 matches. logic behind read line, see core is, , it's number before it. after want add list.
what doing wrong here?
contains
works strings (regexes not supported)... can use line.matches("(\\d+).*")
achieving same.
Comments
Post a Comment