title: How to print out lines after a certain string in java?
body: <p>I am trying to print out all the lines in a certain chapter. This is what I have so far.. a main method which takes in user input of a book name and chapter number which then splits the string to store them in separate data types for the program to use and then calls the method.</p>
  
  <pre><code>    private static List&lt;String&gt; list = new LinkedList&lt;String&gt;();
  
      public static void main(String[] args)  throws Exception{
  
        //findDetailsByWordSearch();
        Scanner scnr = new Scanner(System.in);
        System.out.println("Please enter the name of the file you wish to search and the chapter    number");
        String input = scnr.nextLine();
        String parts[] = input.split(" ");
        int chapterNumber = Integer.parseInt(parts[parts.length -1]);
          String bookName = "";
          for (int i = 0; i &lt; parts.length - 1; i++){
              bookName += parts[i];
          }
        getChapter(bookName, chapterNumber);
  
      }    
  </code></pre>
  
  <p>Next is the method which uses the input from the user to find the book you are looking for, stores the text into an arraylist and also gets the chapter number however, the current code only prints out that one line but I need it to print out all the lines after the "CHAPTER "+chapterNumber point up until a blank space occurs which indicates the end of the chapter. </p>
  
  <pre><code>   public static void getChapter(String bookName, int chapterNumber) throws Exception{  
        String textExtension = ".txt";
        String fileContent;
  
        try {
            BufferedReader reader = new BufferedReader(new FileReader(bookName +textExtension));
              while ((fileContent = reader.readLine()) != null) {
                  list.add(fileContent);    
              }               
              for(int i = 0; i &lt; list.size(); i++){
                  String lines = list.get(i);
                  if(lines.equals("CHAPTER "+chapterNumber)){
                      System.out.println(lines);      
                  }
          }
  
      } catch (Exception e) {
  
          e.printStackTrace();
      }
    }
  </code></pre>
  
  <p>The chapters follow the following format:
  CHAPTER 1 (Text on several lines) followed by a blanked space CHAPTER 2 (Text on several lines) and so on... So the question is how do I print out the text after and in the chapter is found, for example, if the user was searching for say 'Harry 4', the system would find the book harry and read the text into an arraylist then find CHAPTER 4 and print out the text in that chapter until CHAPTER 5. 
  Thanks!</p>