I have a String of text lines.
Some of the lines have a format of "key: value". Others should be ignored.
I have a fixed (pre-defined) list of keys that I needs to extract values for and put into a HashMap.
So, I'm doing something like this:
BufferedReader reader = new BufferedReader(new StringReader(memoText));
reader.lines().forEach(line->{
if(line.startsWith("prefix1")){
// Some code is required here to get the value1
}
else if(line.startsWith("prefix2")){
// Some code is required here to get the value2
}
...
}
Is there a better way of implementing the parsing in Java 8?