I want specific rows from a String to print out.
String:
"
test
test
test
test"
I only want the second and the third row.
How should I do this?
I want specific rows from a String to print out.
String:
"
test
test
test
test"
I only want the second and the third row.
How should I do this?
If you're reading from a file, use a simple FileReader
and use readLine()
method. You can read line by line and take the lines/rows you are interested in.
If you have a simple string containing multiple lines, split by new line character using one of the following options:
String[] values = str.spilt("\\r?\\n|\\r");
# OR
String[] values = str.spilt("\\R");
And then take the required values from the array by index.
System.out.println(values[1]+" and "+ values[2]);