code: public static int getLineCount(String str) {
          if (null == str || str.isEmpty()) {
              return 0;
          }
          int count = 1;
          for (char c : str.toCharArray()) {
              if ('\n' == c) {
                  count++;
              }
          }
          return count;
      }
docs: Counts the number of lines.
  
  @param str the input string
  @return Returns the number of lines terminated by '\n' in string