Java String Line Count countLines(String text)

Here you can find the source of countLines(String text)

Description

count Lines

License

Open Source License

Declaration

private static int countLines(String text) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2006 IBM Corporation and others.
 * 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
 *
 * Contributors:/*  ww  w.  j ava  2  s.c  o m*/
 *     IBM Corporation - Initial API and implementation
 *******************************************************************************/

public class Main {
    private static int countLines(String text) {
        int newLines = 1;
        for (int i = 0; i < text.length(); i++) {
            if (text.charAt(i) == '\n') {
                newLines++;
            }
        }
        return newLines;
    }
}

Related

  1. countLines(String o)
  2. countLines(String s)
  3. countLines(String s)
  4. countLines(String str)
  5. countLines(String text)
  6. countLines(String value)
  7. countLines(String what)
  8. countLines(StringBuffer bigBuffer)
  9. countLineTypes(String line)