I am fairly new to programming so please bear with me. Say I have a large string such as this.
String story = "This is the first line.\n"
+ "This is the second line.\n"
+ "This is the third line\n"
+ "This is the fourth line.\n"
+ "This is the fifth line.";
How would I go about extracting the first, fourth, and so on lines?
If you want to avoid creating arrays, you can use Scanner
Scanner scanner = new Scanner(story);
while(scanner.hasNextLine()) {
System.out.println(scanner.nextLine());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With