Given a string that isn\'t too long, what is the best way to read it line by line?
I know you can do:
BufferedReader reader = new BufferedReader(new
Solution using Java 8
features such as Stream API
and Method references
new BufferedReader(new StringReader(myString))
.lines().forEach(System.out::println);
or
public void someMethod(String myLongString) {
new BufferedReader(new StringReader(myLongString))
.lines().forEach(this::parseString);
}
private void parseString(String data) {
//do something
}