Java String Line Count countLine(CharSequence str)

Here you can find the source of countLine(CharSequence str)

Description

count Line

License

Open Source License

Declaration

public static int countLine(CharSequence str) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2014,2015 Hideki Yatomi
 * All rights reserved. This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License v1.0 which
 * accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

public class Main {
    public static int countLine(CharSequence str) {
        int count = 0;
        for (int i = 0; i < str.length(); i++) {
            if (str.charAt(i) == '\n')
                count++;/*from  w ww  .  j  a  v  a2  s . c o  m*/
        }
        if ((str.length() > 0) && (str.charAt(str.length() - 1) != '\n'))
            count++;
        return count;
    }
}

Related

  1. countLine(String content)
  2. countLine(String contents, int index)
  3. countLineBreaks(final String replacementString)
  4. countLineBreaks(String text)