title: Is there any other method I can use to read lines in my code to perform the function of a readLine()?
body: <p>I am writing a code to count the lines of code with the exception of comments and empty lines but I am stuck at what to use in place of readLine() method with the text variable as it is used only with the BufferedReader class. I do not want to use BufferedReader. I want it to remain String. What can I do to solve this problem?</p>
  <pre><code>public static int count(String text) {
  
          int count = 0;
          boolean commentBegan = false;
          String line = null;
  
          while ((line = text.readLine()) != null) {
              line = line.trim();
              if (&quot;&quot;.equals(line) || line.startsWith(&quot;//&quot;)) {
                  continue;
              }
              if (commentBegan) {
                  if (commentEnded(line)) {
                      line = line.substring(line.indexOf(&quot;*/&quot;) + 2).trim();
                      commentBegan = false;
                      if (&quot;&quot;.equals(line) || line.startsWith(&quot;//&quot;)) {
                          continue;
                      }
                  } else
                      continue;
              }
              if (isSourceCodeLine(line)) {
                  count++;
              }
              if (commentBegan(line)) {
                  commentBegan = true;
              }
          }
          return count;
      }
  private static boolean commentBegan(String line) {}
  private static boolean commentEnded(String line) {}
  private static boolean isSourceCodeLine(String line) {}
  
  </code></pre>
  <p>The text.readLine() that I wrote above does not correlate with I should be done as it is giving an error, I have witten the full code for commentBegan(), commentEnd(), and isSourceCodeLine() methods. All I just need is to solve the problem of readLine() method.</p>