public static final int countLines(String buffer){
  int count=0;
  int index=buffer.indexOf('\n');
  while (index != -1) {
    count++;
    index=buffer.indexOf('\n',index + 1);
  }
  return count;
}

public static final int countLines ( String buffer ) { int count = 0 ; int index = buffer . indexOf ( '\n' ) ; while ( index != - 1 ) { count ++ ; index = buffer . indexOf ( '\n' , index + 1 ) ; } return count ; }
counts the number of lines in the buffer .
