title: Count the number of lines in a Java String
body: <p>Need some compact code for counting the number of lines in a string in Java. The string is to be separated by <code>\r</code> or <code>\n</code>. Each instance of those newline characters will be considered as a separate line. For example -</p>
  
  <pre><code>"Hello\nWorld\nThis\nIs\t"
  </code></pre>
  
  <p>should return 4. The prototype is </p>
  
  <pre><code>private static int countLines(String str) {...}
  </code></pre>
  
  <p>Can someone provide a compact set of statements? I have a solution at here but it is too long, I think. Thank you.</p>