Java Utililty Methods String Line Count

List of utility methods to do String Line Count

Description

The list of methods to do String Line Count are organized into topic(s).

Method

intcountLine(CharSequence str)
count Line
int count = 0;
for (int i = 0; i < str.length(); i++) {
    if (str.charAt(i) == '\n')
        count++;
if ((str.length() > 0) && (str.charAt(str.length() - 1) != '\n'))
    count++;
return count;
...
intcountLine(String content)
count Line
return countHappens('\n', content) + 1;
intcountLine(String contents, int index)
count Line
int count = 0;
if (index < 0 || index > contents.length()) {
    return 0;
for (int i = 0; i < index; i++) {
    if ('\n' == contents.charAt(i))
        count++;
return count;
intcountLineBreaks(final String replacementString)
count Line Breaks
int lineBreaks = 0;
int ignoreNextNAt = -1;
final int len = replacementString.length();
for (int i = 0; i < len; i++) {
    char c = replacementString.charAt(i);
    if (c == '\r') {
        lineBreaks++;
        ignoreNextNAt = i + 1;
...
intcountLineBreaks(String text)
count Line Breaks
char[] chars = text.toCharArray();
int count = 0;
for (int index = 0; index < text.length(); index++) {
    if (chars[index] == '\n') {
        count++;
return count;
...
intcountLineEnds(CharSequence string, int startPos)
Returns the number of line ends considering returns and new lines in string after startPos.
int count = 0;
int i = startPos;
while (i < string.length()) {
    char c = string.charAt(i);
    if ('\r' == c) {
        count++;
        i = advanceIfNextIsNewLine(string, i);
    } else if ('\n' == c) {
...
intcountLines(final String content, final String lineBreak)
count Lines
if (content == null) {
    return -1;
int lastPos = content.indexOf(lineBreak);
int count = 1;
while (lastPos >= 0) {
    lastPos = content.indexOf(lineBreak, lastPos + 1);
    count++;
...
intcountLines(String aMessage)
count Lines
int lastPos = 0;
int count = 1;
while (-1 != (lastPos = aMessage.indexOf("\n", lastPos + 1))) {
    ++count;
return count;
intcountLines(String buffer)
Counts the number of lines in the buffer.
int count = 0;
int index = buffer.indexOf('\n');
while (index != -1) {
    count++;
    index = buffer.indexOf('\n', index + 1);
return count;
IntegercountLines(String data)
Counts the number of lines in this String.
if (data == null) {
    return null;
return data.split("\r\n|\r|\n").length;